android中checkbox自定义样式

博客分类:
  • android ui
1、首先res/drawable中定义编写如下样式: Java代码 收藏代码
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <selectorxmlns:android="http://schemas.android.com/apk/res/android">
  3. <itemandroid:drawable="@drawable/check_true"android:state_checked="true"></item>
  4. <itemandroid:drawable="@drawable/check_true"android:state_selected="true"></item>
  5. <itemandroid:drawable="@drawable/check_true"android:state_pressed="true"></item>
  6. <itemandroid:drawable="@drawable/check_false"></item>
  7. </selector>
2、在layout中添加checkbox控件: Java代码 收藏代码
  1. <CheckBox
  2. android:id="@+id/radioButton1"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:background="@drawable/btn_check"
  6. android:button="@null"
  7. android:checked="true"/>
其中drwable/btn_check为1中顶一个文件名称,另外必须将android:button设置为@null。 @drawable/check_true和@drawable/check_false为checkbox不同状态的图片,可自行设计。

更多相关文章

  1. 【Android】Android清除本地数据缓存代码
  2. CyanogenMod开源代码
  3. android霓虹灯源代码——基础编
  4. Android 代码修改按钮上的图片
  5. Android TextView字体颜色等样式详解

随机推荐

  1. Linux gdb使用基础
  2. Linux gcc使用基础
  3. 2021-02-27:假设一个固定大小为W的窗口,依
  4. TensorFlow-平面曲线拟合
  5. TensorFlow-VGG16模型复现
  6. TensorFlow-手写数字识别(三)
  7. TensorFlow-手写数字识别(二)
  8. 安卓10
  9. 盒模型与常用的居中方式
  10. InnoDB存储引擎简介