Android API中文文檔Button
Android API中文文檔Button是本文要介紹的內容,主要是來了解并學習Android API文檔的內容,具體Android API文檔內容的詳解來看本文。
一、Android API結構
- public class Button extends TextView
- java.lang.Object
- android.view.View
- android.widget.TextView
- android.widget.Button
已知直接子類
- CompoundButton
已知間接子類
- CheckBox
- RadioButton
- ToggleButton
二、Android API概述
Android API中代表一個按鈕部件。用戶通過按下按鈕,或者點擊按鈕來執行一個動作。以下是一個按鈕在activity中典型的應用:

然后,你能在xml布局中通過button的android:onClick屬性指定一個方法,以替代在activity中為button設置OnClickListener。例如:

現在,當用戶點擊按鈕時,Android系統調用activity的selfDestruct(View)方法。為了正確執行,這個方法必須是public并且僅接受一個View類型的參數。例如:

三、Android API按鈕樣式
每個按鈕的樣式默認為系統按鈕的背景,不同的設備、不同的平臺版本有不同按鈕風格。如你不滿意默認的按鈕樣式,想對其定制以符合您應用程序的設計,那么你能用state list drawable替換按鈕的背景圖片。一個狀態列表drawable是一個在XML中定義的drawable資源,根據當前按鈕的狀態改變其圖片。一旦你在XML中定義了一個狀態列表drawable,你可以將它應用于你的android:background屬性。欲了解更多信息和示例,參見State List Drawable.
實現一個按鈕的例子可參見Form Stuff tutorial。
小結:Android API中文文檔Button的內容介紹完了,希望通過Android API內容的學習能對你有所幫助!