Android API 中文(13) —— ToggleButton

來源:互聯網
上載者:User

前言

  關鍵字: Android API 中文,Android 中文 API,android sdk 中文

  本章翻譯的是android.widget.ToggleButton,譯為開關按鈕 。歡迎更多朋友一起參與Android API 的中文翻譯行動!再次感謝移動社區提供的積分支援!我的郵箱over140@gmail.com。

聲明

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

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

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

 

版本

  Android 2.2 r1

本文

  一、結構

    public class ToggleButton extends CompoundButton

 

    java.lang.Object

        android.view.View

              android.widget.TextView

                      android.widget.Button

                            android.widget.CompoundButton

                                   android.widget.ToggleButton

 

  二、 類概述

    

    通過一個帶有亮度指示同時預設文本為“ON”或“OFF”的按鈕顯示選中/未選中狀態。

 

  三、XML屬性

屬性名稱

描述

android:disabledAlpha

設定按鈕在禁用時透明度。

 

android:textOff

未選中時按鈕的文本

android:textOn

選中時按鈕的文本

 

  四、公用方法

         public CharSequence getTextOff ()

         返回按鈕未選中時的文本。

                   傳回值

                            文本

 

         public CharSequence getTextOn ()

         返回按鈕選中時的文本。

                   傳回值

                            文本

 

         public void setBackgroundDrawable (Drawable d)

         設定指定的可繪製(譯者註:片)為背景,或移除背景。如果讓背景有邊距,這個視圖的邊距就是背景的邊距。然而,當背景被刪除時,這個視圖的邊距不能被觸摸。如果需要設定邊距,請使用方法setPadding(int, int, int, int)。

(譯者註:如果設定移除背景整個就不顯示了,此外設定背景後選中和被選中的圖片也不顯示了,如: ,實現代碼:

 

                   參數

                            d      設定可繪製(譯者註:片)為背景,或設定為空白移除背景。

 

         public void setChecked (boolean checked)

         改變按鈕的選中狀態。

                   參數

                            checked true讓按鈕選中,false讓按鈕不選中

 

         public void setTextOff (CharSequence textOff)

         設定按鈕未選中時顯示的文本。

                   參數

                            textOff    文本

 

         public void setTextOn (CharSequence textOn)

         設定按鈕選中時顯示的文本。

                   參數

                            textOn    文本

 

 

  五、受保護方法

         protected void drawableStateChanged ()

         在檢視狀態的變化影響到所顯示可繪製的狀態時調用這個方法。

         確保在覆蓋時中調用父類方法(譯者註:super. drawableStateChanged ())。

 

         protected void onFinishInflate ()

         XML檔案載入視圖完成時調用。這個函數在載入的最後階段被調用,所有的子視圖已經被添加。

         即使子類重寫了onFinishInflate方法,也應該始終確保調用父類方法(譯者註:super. onFinishInflate()),使系統能夠調用。 

 

  六、下載

    http://download.csdn.net/source/2746654

 

  八、系列

    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

 

結束

  至今翻譯組已經擴充至七人,感謝他們的熱心參與,期待每天發布一篇甚至多篇譯稿那天早日到來。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.