我正试图通过ABOUT按钮来收听点击,以便从显示三个按钮和图片的屏幕转到另一个显示一些文字的屏幕。
这是我的主要java文件(MainActivity.java)
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context cont = this;
Button aButton = (Button) findViewById(R.id.ab_button);
aButton.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(cont, AboutActivity.class);
startActivity(intent);
}
});
}
这是我关于about按钮的第二个java文件(AboutActivity.java):
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class AboutActivity extends Activity {
public void onCreate(Bundle about){
super.onCreate(about);
setContentView(R.layout.activity_about);
TextView briText = (TextView) findViewById(R.id.about_b2);
briText.setText("Goodie");
}
}
这是显示图片和按钮(activity_main.xml)的主要xml文件:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_b"
android:id="@+id/ab_button"
android:shadowColor="#8e2300"
android:background="@drawable/oval_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share_button"
android:id="@+id/share_button"
android:shadowColor="#8e2300"
android:onClick="shareActivity"
android:background="@drawable/oval_button"
这是显示文本(activity_about.xml)的xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/back_to_work_rel">
<TextView android:text="@string/about_bac"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/about_b2" />
</RelativeLayout>
清单文件(AndroidManifest.xml):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brian.eggalong" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity"
android:parentActivityName=".MainActivity"
android:label="@string/about_bac">
</activity>
</application>
</manifest>
每次单击“关于”按钮时,都没有任何反应。任何帮助将不胜感激。