很多人认为要自定义一个checkBox的样式,要自定义一个checkBox的背景切换XML然后赋值给布局XML中的background。另外将android:button="@null"就行了。。。
事实上,再我们只有复选框的时候这个方式是可行的。但是再系统的checkBox是可以设置text的。这时候我们再使用android:text="复选框选项"就会发现问题了。长话段说,实际的用法:
先再res/drawable文件夹下编写一个名为checkbox_button.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/check_box_checked"/>
<item android:state_checked="false" android:drawable="@drawable/check_box"/>
</selector>


然后再布局XML中引用这个复选框的按钮样式。编写如下:
<CheckBox
android:id="@+id/loginZDDLCbx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loginZDDLStr"
android:textColor="#ff000000"
android:button="@drawable/check_box_back"
/>
这样我的CheckBox就可以设置带有文字了。并且文字的区域也是CheckBox的点击相应区域。

更多相关文章

  1. 【Android(安卓)界面效果10】Android中View,ViewGroup,Window之
  2. android 基于ijkplayer项目进行的播放器
  3. android 判断横竖屏问题的详解
  4. Android进阶笔记10:Android(安卓)万能适配器
  5. [置顶] Android列表收缩与展开仿QQ好友列表(非常详细,附源码)
  6. 自定义 Android(安卓)对话框 (AlertDialog) 的样式
  7. Android(安卓)5.0 Activity切换动画
  8. Android——自定义Toast(含源码下载)
  9. Android布局文件xml

随机推荐

  1. 技术揭秘:Android究竟比iOS差在哪里?
  2. android 兼容API的检查
  3. Android(安卓)仿iphone提醒事项(一)
  4. 今日头条面试(android)
  5. Android中如何编译运行系统自带桌面Launc
  6. android支持的codec一览
  7. Android(安卓)监听键盘弹出关闭
  8. android 代码优化
  9. AIDL和远程Service调用
  10. Android的Logcat命令详解:翻译Enabling lo