android 自定義checkbox 樣式
有些時候需要根據項目需求自定義CheckBox 的樣式,步驟如下:
1.首先在drawable文件夾中添加drawable文件my_checkbox.xml
2.在values文件夾下的styles.xml文件中添加CustomCheckboxTheme樣式
<style name="custom_checkbox" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/my_checkbox</item> </style>
3.在CheckBox中使用CustomCheckboxTheme樣式
<CheckBox android:id="@+id/checked" style="@style/custom_checkbox" android:layout_width="40dip" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:checked="false" />
使用的圖片資源
checkbox_normal.png 未選中狀態圖片
checkbox_pressed.png 選中狀態圖片
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!