:
首先先定义一个CheckBox。 关键是style="@style/MyCheckBox"
<CheckBox
android:id="@+id/login_cb_quite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
ndroid:textColor="#7fffffff"
android:text="@string/opt_silent"
style="@style/MyCheckBox" />
style.xml:
<resources>
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:textSize">16.0sp</item>
<item name="android:textColor">@color/qq_checkbox_text_color</item>
<item name="android:paddingLeft">28.0px</item>
<item name="android:button">@drawable/qq_btn_check</item>
</style>
</resources>
这里的关键是<item name="android:button">@drawable/qq_btn_check</item>
这里将button的样式设置成qq_btn_check.xml中的设置
qq_btn_check.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:state_checked="true" android:drawable="@drawable/btn_check_on" />
<item android:state_window_focused="false" android:state_enabled="true"
android:state_checked="false" android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true"
android:state_pressed="true" android:drawable="@drawable/btn_check_on_pressed" />
<item android:state_enabled="true" android:state_checked="false"
android:state_pressed="true" android:drawable="@drawable/btn_check_off_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:state_checked="true" android:drawable="@drawable/btn_check_on_selected" />
<item android:state_focused="true" android:state_enabled="true"
android:state_checked="false" android:drawable="@drawable/btn_check_off_selected" />
<item android:state_enabled="true" android:state_checked="false"
android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true"
android:drawable="@drawable/btn_check_on" />
</selector>
设置当选中和未选中的的样式图都可以定义自己想要设置的样式
一个自定义的checkBox就出来了
分享到:
相关推荐
Android自定义checkbox的代码
自定义仿腾讯checkbox。包含点击、聚焦等个各种操作,都会显示出不同的状态图片。
如何自定义CheckBox的样式 1:首先在布局文件中添加CheckBox的控件配置,如: <CheckBox android:id="@+id/button1" style="@style/CheckBoxStyles"//这里就是用户可以自定CheckBox的样式 android:layout_width...
简单实现自定义checkbox控件四种选择状态的图片样式
本文通过实例代码演示如何在Android中如何自定义CheckBox,实现的效果很好,有需要的可以参考借鉴。
这是一个关于自定义checkbox、RadioButton, Switch, SwitchPreference , CheckPreference 等控件颜色的 demo。 让控件显示我们想要的颜色,同时又不影响使用Android5.0提供的动画,何乐而不为。
项目中需要有个Dialog全选对话框,点击全选全部选中,取消全选全部取消。下午查了些资料,重写了一下Dialog对话框。把代码放出来。
主要介绍了Android中自定义Checkbox控件实例,本文使用两张图片来美化Checkbox组件,需要的朋友可以参考下
Android自定义RadioButton和CheckBox样式,重写RadioButton的onDraw()方法,实现颜色选择器效果。
一个简单实现自定义带CheckBox的ListView。
本demo实现功能为:Expandablelistview子项checkBox先获取已选择状态,在次过程中可修改子项选择,最终提交选择子类的项,并打印相关数据
Android开发中自定义CheckBox
主要介绍了android自定义checkbox的样式示例,需要的朋友可以参考下
大家是不是对系统自带的CheckBox产生乏味感了呢?今天这篇文章给大家带来的是一款全新的CheckBox,下面来一起看看下面的CheckBox吧!有需要的朋友们可以参考借鉴。
Android 自定义横向滚动条。当你的横向字段或者表格很多时候,显示不下内容,可以使用很想滚动条进行滚动。竖向方面我添加了listview进行添加数据。两者滚动互不干扰。长按listview的item出现checkbox,可以进行多选...
一个简单的拥有丰富自定义内容的CheckBox多选框集成Gradlecompile 'com.bigmercu.cBox:cbox:1.08'Mavenallprojects { repositories { jcenter() maven { url '...
最近抽了点时间,针对android一些控件的样式做了完整自定义,主要包括Spinner的样式完全自定义、RadioButton[CheckBox样式雷同]样式完全自定义、Rating样式自定义,代码已经经过测试,有需要的可以下载