android 控件之checkbox自定义样式
2014-12-03 19:39
681 查看
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
2.在values文件夹下的styles.xml文件中添加MyCheckBox样式。
3.在布局文件使用MyCheckBox样式
相关图片资源:
check_pressed:
check_normal:
界面截图:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/checkbox_pressed" android:state_checked="true"/> <item android:drawable="@drawable/checkbox_normal" android:state_checked="false"/> <item android:drawable="@drawable/checkbox_normal"/> </selector>
2.在values文件夹下的styles.xml文件中添加MyCheckBox样式。
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <span style="color:#ff0000;"><style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/checkbox_selector</item> <item name="android:paddingLeft">25.0dip</item> <item name="android:maxHeight">10.0dip</item> </style></span> </resources>
3.在布局文件使用MyCheckBox样式
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:layout_marginRight="10sp" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sports" android:textSize="18sp" > </TextView> <span style="color:#ff0000;"> <CheckBox style="@style/MyCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" /></span> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/distance" android:textSize="18sp" > </TextView> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10sp" android:layout_marginRight="10sp" android:orientation="horizontal" > <Button android:layout_width="24sp" android:layout_height="24sp" android:background="@drawable/reduce" > </Button> <SeekBar android:id="@+id/seekbar" android:layout_width="250sp" android:layout_height="24sp" android:max="30" android:progress="10" android:progressDrawable="@drawable/bg_bar" android:thumb="@drawable/thumb_bar" /> <Button android:layout_width="24sp" android:layout_height="24sp" android:background="@drawable/add" > </Button> </LinearLayout> </LinearLayout>
相关图片资源:
check_pressed:
check_normal:
界面截图:
相关文章推荐
- Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、
- Android中checkbox控件的自定义样式设置
- Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、
- Android中自定义checkbox样式
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- Android中自定义checkbox样式 two
- Android中自定义checkbox样式
- Android 自定义CheckBox 样式
- Android知识整理(3) 两种自定义样式的Checkbox
- Android 自定义CheckBox 样式
- Android中自定义checkbox样式
- 替换Android控件默认样式 (例子:自定义进度条)
- android中checkbox自定义样式
- android自定义radiobutton、checkbox样式
- android自定义按钮控件样式 (转)
- android中checkbox自定义样式
- android 自定义checkbox 样式
- Android 自定义Checkbox显示样式
- Android中自定义CheckBox样式
- Android中自定义CheckBox样式