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

来源:互联网 发布:凹陷性疤痕 知乎 编辑:程序博客网 时间:2024/05/01 16:26

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 {@Overrideprotected 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() {@Overridepublic 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>



0 0
原创粉丝点击