Android 2.2 r1 API 中文文档系列(12) —— Button
前言
?
截止到這篇,總共翻譯了Android API十二篇,其中有兩篇是翻譯組另外一名成員提供。翻譯工作量雖大、雖難,但不管是對自己還是對別人都是巨大的幫助,少則一篇不嫌少,多則十篇不嫌多,再次呼吁大家的熱心參與Android api 中文翻譯,我的郵箱over140@gmail.com。
?
?
聲明
歡迎轉載,但請保留文章原始出處:)
?
?? 農民伯伯:http://over140.blog.51cto.com/
?
正文
一、結構
public class Button extends TextView
java.lang.Object
?? android.view.View
? ?? ??? android.widget.TextView
? ?? ? ??? ??? android.widget.Button
?
已知直接子類
CompoundButton
已知間接子類
CheckBox, RadioButton, ToggleButton
?
二、概述
?
代表一個按鈕部件。用戶通過按下按鈕,或者點擊按鈕來執行一個動作。以下是一個按鈕在activity中典型的應用:
然后,你能在xml布局中通過button的android:onClick屬性指定一個方法,以替代在activity中為button設置OnClickListener。例如:
現在,當用戶點擊按鈕時,Android系統調用activity的selfDestruct(View)方法。為了正確執行,這個方法必須是public并且僅接受一個View類型的參數。例如:
?
三、按鈕樣式
?
每個按鈕的樣式默認為系統按鈕的背景,不同的設備、不同的平臺版本有不同按鈕風格。如你不滿意默認的按鈕樣式,想對其定制以符合您應用程序的設計,那么你能用state list drawable替換按鈕的背景圖片。一個狀態列表drawable是一個在XML中定義的drawable資源,根據當前按鈕的狀態改變其圖片。一旦你在XML中定義了一個狀態列表drawable,你可以將它應用于你的android:background屬性。欲了解更多信息和示例,參見State List Drawable.
實現一個按鈕的例子可參見Form Stuff tutorial
?
?
四、XML屬性
參見Button、TextView、View的XML屬性。
?
五、下載
CSDN: http://download.csdn.net/source/2739376
?
六、系列
?
Android 2.2 API 中文文檔系列(1) —— TextView
Android 2.2 API 中文文檔系列(2) —— EditText
Android 2.2 API 中文文檔系列(3) —— AccessibilityService
Android 2.2 API 中文文檔系列(4) —— Manifest
Android 2.2 API 中文文檔系列(5) —— View
Android 2.2 API 中文文檔系列(6) —— ImageView
Android 2.2 API 中文文檔系列(7) —— ImageButton
Android 2.2 API 中文文檔系列(8) —— QuickContactBadge
Android 2.2 API 中文文檔系列(9) —— ZoomButton
Android 2.2 r1 API 中文文檔系列(10) —— CheckBox
Android 2.2 r1 API 中文文檔系列(11) —— RadioButton
?
結束
?
取之于網上中文資料學習,饋之于網上而供他人學習。
?
總結
以上是生活随笔為你收集整理的Android 2.2 r1 API 中文文档系列(12) —— Button的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我为什么赞成房产税
- 下一篇: 服务器硬盘SAS与SATA区别介绍