Android游戏开发系统控件-Button
Button(按钮)是一个常用的系统小组件,很小但是在开发中最常用到。一般通过与监听器使用,从而触发一些特定事件。
下面为一个Andriod项目“ButtonProject”,对应的代码如下
项目功能:点击按钮触发事件
代码分别为:
main.xml
string.xml
ButtonProject.java
项目运行效果图:


代码清单:
=》》main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/tv"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- <Button
- android:id="@+id/btn_ok"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/btn_ok"
- />
- <Button
- android:id="@+id/btn_cancel"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/btn_cancel"
- />
- </LinearLayout>
