歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android游戲開發系統控件-Button

Android游戲開發系統控件-Button

日期:2017/3/1 10:22:56   编辑:Linux編程

Android游戲開發系統控件-Button

Button(按鈕)是一個常用的系統小組件,很小但是在開發中最常用到。一般通過與監聽器使用,從而觸發一些特定事件。

下面為一個Andriod項目“ButtonProject”,對應的代碼如下

項目功能:點擊按鈕觸發事件

代碼分別為:

main.xml

string.xml

ButtonProject.java

項目運行效果圖:

代碼清單:

=》》main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/tv"
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/hello" />
  11. <Button
  12. android:id="@+id/btn_ok"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"
  15. android:text="@string/btn_ok"
  16. />
  17. <Button
  18. android:id="@+id/btn_cancel"
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content"
  21. android:text="@string/btn_cancel"
  22. />
  23. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved