实例8:实现应用对话框主题的关于Activity

本文介绍了一个简单的Android应用程序中实现导航的方法。通过定义布局文件、创建AboutActivity类,并为MainActivity中的按钮添加点击事件来启动新的Activity页面。此外,还介绍了如何在AndroidManifest.xml中配置新Activity。

1、布局文件

<LinearLayout 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"
    >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="点击查看详情" />

</LinearLayout>

2、AboutActivity类

public class AboutActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LinearLayout ll = new LinearLayout(this);//创建线性布局管理器对象
		ll.setPadding(20, 20, 20, 20);
		TextView tv = new TextView(this);//创建TextView对象
		tv.setTextSize(24);//设置字体大小
		tv.setText(R.string.about);//设置要显示的内容
		ll.addView(tv);//将TextView添加到线性布局管理器中
		setContentView(ll);//设置该Acitivity显示的内容视图
	}
}

3、MainActivity的按钮添加点击事件

Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, AboutActivity.class);//创建Intent对象
				startActivity(intent);//启动About Activity
			}
		});

4、在AndroidManifest.xml文件中配置AboutActivity

<activity 
            android:icon="@drawable/ic_launcher"
            android:name=".AboutActivity"
            android:label="关于...."
            android:theme="@android:style/Theme.Dialog"></activity>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值