android 自定义checkbox 大小 图片
2011-09-07 16:27
393 查看
在编程过程中使用android自带的checkbox显示过大,在网上找了很多文章,终于使用自定义的checkbox使显示更加美观。
网上说:这个控件其实就是个TextView加了个图片,你只要做两张png的图片,在darwable中用xml定义好点击事件,再在你的控件上把这个当背景引进来就可以了。但是这样做了以后显示效果还是不佳。说说我的做法吧:
1、找两张图片http://findicons.com/search/checkbox# 分别为选中和没选中的。命名为checkbox和checkbox_empty
2、在drawable中创建文件checkbox_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/checkbox" /><!--选中时效果-->
<item android:state_checked="false"
android:drawable="@drawable/checkbox_empty" /><!--未选中时效果-->
<!-- 修改成你自己的图片就可以了 -->
</selector>
注意:这里的状态是android:state_checked
3、在values中创建styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<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>
</resources>
4、在你的CheckBox中添加属性:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyCheckBox"
/>
经过以上步骤应该可以了。我对style和selector的使用也不熟悉,大家一起学习~
网上说:这个控件其实就是个TextView加了个图片,你只要做两张png的图片,在darwable中用xml定义好点击事件,再在你的控件上把这个当背景引进来就可以了。但是这样做了以后显示效果还是不佳。说说我的做法吧:
1、找两张图片http://findicons.com/search/checkbox# 分别为选中和没选中的。命名为checkbox和checkbox_empty
2、在drawable中创建文件checkbox_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/checkbox" /><!--选中时效果-->
<item android:state_checked="false"
android:drawable="@drawable/checkbox_empty" /><!--未选中时效果-->
<!-- 修改成你自己的图片就可以了 -->
</selector>
注意:这里的状态是android:state_checked
3、在values中创建styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<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>
</resources>
4、在你的CheckBox中添加属性:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyCheckBox"
/>
经过以上步骤应该可以了。我对style和selector的使用也不熟悉,大家一起学习~
相关文章推荐
- android中自定义checkbox大小和图片
- android中自定义checkbox大小和图片
- android中自定义checkbox的图片和大小
- android中自定义checkbox大小和图片
- android中自定义checkbox大小和图片
- android中自定义checkbox大小和图片
- android中自定义checkbox大小和图片
- android中自定义checkbox大小和图片
- android中自定义checkbox的图片和大小
- android中自定义checkbox大小和图片
- android 自定义TextView,设置DrawableLeft图片的大小
- Android 自定义imageview 图片宽度固定大小高度按比例自适应
- Android的CheckBox控件设置自定义图片
- Android CheckBox自定义图片没效果--解决办法
- Android 自定义imageview 图片高度固定大小宽度按比例自适应
- android自定义CheckBox和RadioButton中文字和图片之间距离
- Android 自定义view-如何设置TextView drawableLeft 图片大小?
- Android 自定义camera压缩图片到指定大小
- android中的CheckBox改变背景图片后图片显示大小不正确的问题
- android 调用系统自带的选择图片 然后进行自定义大小裁剪