Android 2.2 r1 API 中文文檔系列(12) —— Button

來源:互聯網
上載者:User

 

前言

  截止到這篇,總共翻譯了Android API十二篇,其中有兩篇是翻譯組另外一名成員提供。翻譯工作量雖大、雖難,但不管是對自己還是對別人都是巨大的協助,少則一篇不嫌少,多則十篇不嫌多,再次呼籲大家的熱心參與Android api 中文翻譯,我的郵箱over140@gmail.com。

聲明

  歡迎轉載,但請保留文章原始出處:)

    部落格園:http://www.cnblogs.com

    農民伯伯: http://www.cnblogs.com/over140/

 

本文

  一、結構

    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

 

結束

   取之於網上中文資料學習,饋之於網上而供他人學習。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.