安卓——自定义checkbox图标
来源:互联网 发布:mac关闭快捷键 编辑:程序博客网 时间:2024/05/16 09:47
通过自定义checkbox和点击响应事件说说<selector>
1.首先在drawable文件夹中添加checkbox_style.xml
<pre class="html" name="code"><span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"></span>
<span style="font-size:14px;"><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"/></span>
<span style="font-size:14px;"></selector></span>
2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
<pre class="html" name="code"><span style="font-size:14px;"><style name="</span><span style="font-size:14px;color:#ff0000;">CustomCheckboxTheme</span><span style="font-size:14px;">" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/</span><span style="font-size:14px;color:#3333ff;">checkbox_style</span><span style="font-size:14px;"></item> </style> </span>
<span style="font-size:18px;">3.在布局文件中使用</span><span style="font-size:18px;color:#ff0000;">CustomCheckboxTheme</span><span style="font-size:18px;">样式。</span>
<span id="_xhe_cursor"><span style="font-size:18px;"></span></span>
<span style="font-size:14px;"><CheckBox android:id="@+id/select_all" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/</span><span style="font-size:14px;color:#ff0000;">CustomCheckboxTheme</span><span style="font-size:14px;">" /> </span><span style="font-size:18px;"> </span>
以上内容转自 http://blog.csdn.net/zuolongsnail/article/details/7106586 ------------------------------------
通过查阅总结,首先android的selector是在drawable/xxx.xml中配置的,常用属性有:
android:state_selected 选中
android:state_focused 获得焦点
android:state_pressed 点击
android:state_enabled 设置是否响应事件,指所有事件
根据这些状态同样可以设置button的selector效果。也可以设置selector改变button中的文字状态。
以下就是配置button中的文字效果:drawable/button_font.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="#FFF" />
<item android:state_focused="true" android:color="#FFF" /> <item android:state_pressed="true" android:color="#FFF" /> <item android:color="#000" /></selector>
Button还可以实现更复杂的效果,例如渐变啊等等。drawable/button_color.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <!-- 定义当button 处于pressed 状态时的形态。--> <shape> <gradient android:startColor="#8600ff" /> <stroke android:width="2dp" android:color="#000000" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp" /> </shape> </item> <item android:state_focused="true"> <!-- 定义当button获得focus时的形态--> <shape> <gradient android:startColor="#eac100" /> <stroke android:width="2dp" android:color="#333333" color="#ffffff" /> <corners android:radius="8dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp" /> </shape> </item></selector>最后,需要在包含button的xml文件里添加两项。假如是main.xml 文件,我们需要在<Button />里加两项。
android:focusable="true"
android:backgroud="@drawable/button_color"
这样当你使用Button的时候就可以甩掉系统自带的那黄颜色的背景了,实现个性化的背景。
0 0
- 安卓——自定义checkbox图标
- 安卓自定义电量显示图标
- 自定义android checkbox的图标和文字
- 安卓自定义带删除图标的输入框EditView
- 安卓自定义带删除图标的输入框EditView
- 安卓开发之自定义View通过Drawable绘制图标
- 安卓CheckBox使用
- 安卓图标
- 安卓图标功能
- 安卓应用图标
- html自定义checkbox、radio、select —— checkbox、radio篇
- 安卓开发——自定义ViewGroup
- 安卓学习之—自定义Dialog
- 安卓复选框(Checkbox)
- 安卓CheckBox看不到文字
- Android 自定义 CheckBox 文字与图标的方向
- 安卓开发——改变checkbox控件框的颜色
- 安卓开发 没有图标
- 如何查看windows系统是否被远程登录
- Eclipse远程Debug
- js语法2
- 开发集成工具phabricator
- c++primer第五版第十章练习
- 安卓——自定义checkbox图标
- iOS开发:苹果应用商店审核指南中文翻译
- ArcGIS API for javascript开发笔记(六)——REST详解及如何使用REST API调用GP服务
- SQL学习:SQLCookBook源代码-mysql版本(1)
- IOS CoreMotion
- STM32笔记:使用SysTick测量程序的运行时间
- Android快速开发系列 10个常用工具类
- HTML5新增标签1
- jsp标签&jstl