我是 android 新手,当我点击按钮时,什么也没有发生。所以请帮助摆脱这个问题。提前致谢。
MainActivity.java
import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.hom_sel_enter_btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.menu_selection_layout);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/loadingscreen">
<RelativeLayout>
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hom_sel_enter_btn"
android:layout_gravity="center_horizontal"
android:soundEffectsEnabled="true"
android:background="@drawable/ent_sel_bn" >
</Button>
</RelativeLayout>
</RelativeLayout>
app_menu_sel.java
导入 android.app.Activity;导入android.os.Bundle;导入android.view.View;导入 android.view.View.OnClickListener;导入android.widget.Button;
public class app_menu_sel extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_selection_layout);
Button btn1 = (Button)findViewById(R.id.hom_but_selection_top);
btn1.setOnClickListener(btnListener);
}
private OnClickListener btnListener = new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.activity_main);
}
};
}
menu_selection_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/hom_but_selection_top"
android:clickable="true"
android:background="@drawable/home">
</Button>
</LinearLayout>
</LinearLayout>
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.display"
android:versionCode="1"
android:versionName="1.0" >
<application>
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity>
android:name="com.example.display.MainActivity"
android:label="@string/app_name"
android:screenOrientation = "portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.display.app_menu_sel"
android:label="@string/app_menu_sel"
android:screenOrientation = "portrait">
</activity>
</application>
</manifest>