zoukankan      html  css  js  c++  java
  • [Android实例] 更改CheckBox的样式

    首先在styles.xml添加如下的自定义样式:

    1.         <style name="mycheckbox" parent="@android:style/Widget.CompoundButton.CheckBox">
    2.         <item name="android:button">@drawable/my_checkbox</item>
    3.         </style>
    复制代码

    my_checkbox.xml的内容为:

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3.         <item android:state_checked="true" android:drawable="@drawable/checkbox_pressed" />                                                                                        
    4.     <item android:state_checked="false" android:drawable="@drawable/checkbox" />
    5.      <item android:drawable="@drawable/checkbox" />                                                                                                
    6. </selector>
    复制代码

    使用自定义样式的代码段:

    1.                 <CheckBox
    2.                                 android:id="@+id/checked" 
    3.                                 android:layout_alignParentRight="true"
    4.                                 android:layout_marginRight="10dip"
    5.                                 android:layout_centerVertical="true"
    6.                                 android:layout_width="40dip" 
    7.                                 android:layout_height="wrap_content"
    8.                                 android:checked="false"
    9.                                 style="@style/mycheckbox" 
    10.                                 />
    复制代码

    添加两张图片checkbox_pressed.png、checkbox.png

    http://www.eoeandroid.com/forum.php?mod=viewthread&tid=148630

  • 相关阅读:
    使用Navicat for Oracle新建表空间、用户及权限赋予---来自烂泥
    NonAction与ChildActionOnly
    C# Monitor的Wait和Pulse方法使用详解
    机械键盘简介
    【转载】 中小型研发团队架构实践
    BinaryReader 自己写序列化
    显式接口实现
    AssemblyVersion和AssemblyFileVersion的区别
    自定义设置程序集版本重定向和程序集位置的信息
    单例模式中的属性实现
  • 原文地址:https://www.cnblogs.com/cmblogs/p/4389169.html
Copyright © 2011-2022 走看看