如何自定義CheckBox多選框的樣式

2021-07-22 06:34:57 字數 1321 閱讀 9638

安卓自帶的checkbox有時候不能滿足專案需求,這時候就需要自己定製一套樣式出來。具體實現方法如下:

第一:首先需要找幾張自己想要定義成的:

把上面的放到drawable-xhdpi或者mipmap目錄下。

第二:在res目錄下面建立drawable資料夾,drawable下面建立xml檔案checkbox_selector.xml**如下:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="" >

android:state_checked="false"

android:state_pressed="true"

android:drawable="@drawable/grid_check_off_press">

item>

android:state_checked="false"

android:drawable="@drawable/grid_check_off">

item>

android:state_checked="true"

android:state_pressed="true"

android:drawable="@drawable/grid_check_on_press" />

android:state_checked="true"

android:drawable="@drawable/grid_check_on">

item>

selector>

到這裡工作已經完成1/2了。

第三:在stytle檔案中新建樣式:

name="android:button">@drawable/checkbox_selectorsitem>

name="android:paddingleft">10.0dipitem>

name="android:height">35.0dipitem>

第四:在布局中使用就好啦,引入stytle樣式。

android:id="@+id/checkbox1"

style="@style/mycheckbox"

android:layout_width="wrap_content"

android:layout_height="35dp"

android:layout_alignleft="@+id/tv"

android:layout_below="@+id/tv"

android:layout_margintop="84dp"

android:text="自定義樣式" />

自定義checkbox元件

1 編寫自定義元件類 public class myactivity extends activity see the form stuff tutorial.xml attributes see public class ipadmessagecheckbox extends compoundbu...

checkbox樣式自定義

原理 隱藏 input 預設的樣式 通過label for input 去對映 checkbox 選中和未選中狀態的轉換 上 html css input type checkbox label label.chbox label before input type checkbox checked...

自定義CheckBox樣式

極力推薦文章 歡迎收藏 android 乾貨分享 閱讀五分鐘,每日十點,和您一起終身學習,這裡是程式設計師android 自定義樣式 自定義選擇器效果 自定義素材 為checkbox標籤自定義樣式 android中自帶的checkbox樣式比較醜,為了美化checkbox可使用一下方法。實現效果如下...