zoukankan      html  css  js  c++  java
  • Android 自定义CheckBox 样式

    新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式。

    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:state_checked="true" android:state_pressed="true"
                    android:drawable="@drawable/focused" ;/>
            <item android:state_checked="false" android:state_pressed="true"
                    android:drawable="@drawable/normal" ;/>
            <item android:state_checked="false" android:drawable="@drawable/normal" ;/>
            <item android:state_checked="true" android:drawable="@drawable/focused" ;/>
    </selector>

    state_checked 选中状态 state_pressed按下状态 
    即分别设置checkbox选中和没选中时,按下和没按下时显示的图片. 
    应用到Checkbox与Button不同,并不是设置Background属性,而是设置style属性,所以我们要写一个style。 
    在strings.xml写一个style,

    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:state_checked="true" android:state_pressed="true"
                    android:drawable="@drawable/focused" ;/>
            <item android:state_checked="false" android:state_pressed="true"
                    android:drawable="@drawable/normal" ;/>
            <item android:state_checked="false" android:drawable="@drawable/normal" ;/>
            <item android:state_checked="true" android:drawable="@drawable/focused" ;/>
    </selector>

    应用到Checkbox:

    <CheckBox android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            style="@style/MyCheckBox"
    ;        />
  • 相关阅读:
    北京六环附近及往内的可驾驶道路网络(路网graph为连通图)
    OSM数据处理-python工具包
    小程序踩坑
    小程序基本配置
    JavaScript 基础(四):Array
    MYSQL--慎用group_concat()
    真正高效的SQLSERVER分页查询
    PhpStorm Git 操作
    linux 查看当前目录文件的大小
    @PostConstruct和@PreDestroy的使用说明
  • 原文地址:https://www.cnblogs.com/luenmicro/p/3446963.html
Copyright © 2011-2022 走看看