【轉】Android學習基礎自訂Checkbox組件

來源:互聯網
上載者:User

標籤:

原文網址:http://forum.maiziedu.com/thread-515-1-1.html

heckbox組件是一種可同時選中多項的基礎控制項,即複選框,在android學習中,Checkbox是一款非常重要的UI組件,由於它的展現形式美觀性和協調性不符合我們的需求,我們需要自訂這個組件,方法很簡單,只需要增加修改xml檔案即可。

首先需要準備兩張圖片,一張是選中的圖片,一張是未選中的圖片。

android開發設定選擇框

在drawable下建立檔案custom_checkbox.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3.     <item android:state_checked="true" android:drawable="@drawable/checked"></item>
  4.   <item android:state_checked="false" android:drawable="@drawable/unchecked"></item>
  5.   <item android:drawable="@drawable/unchecked"></item><!-- The default one -->
  6. </selector>
複製代碼



android開發應用自訂

設定button屬性值為上面定義的custom_checkbox。

  1. <CheckBox
  2.   android:layout_width="wrap_content"
  3.     android:layout_height="wrap_content"
  4.     android:button="@drawable/custom_checkbox"
  5. />
複製代碼



以上就實現了Checkbox組件自訂,有興趣的網友可以運行看看結果。

【轉】Android學習基礎自訂Checkbox組件

聯繫我們

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