• 【转】Android学习基础自定义Checkbox组件


    原文网址:http://forum.maiziedu.com/thread-515-1-1.html

    heckbox组件是一种可同时选中多项的基础控件,即复选框,在android学习中,Checkbox是一款非常重要的UI组件,由于它的展现形式美观性和协调性不符合我们的需求,我们需要自定义这个组件,方法很简单,只需要增加修改xml文件即可。

    首先需要准备两张图片,一张是选中的图片,一张是未选中的图片。

    android开发设置选择框

    在drawable下新建文件custom_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/checked"></item>
    4.   <item android:state_checked="false" android:drawable="@drawable/unchecked"></item>
    5.   <item android:drawable="@drawable/unchecked"></item><!-- The default one -->
    6. </selector>
    复制代码



    android开发应用自定义

    设置button属性值为上面定义的custom_checkbox。

    1. <CheckBox
    2.   android:layout_width="wrap_content"
    3.     android:layout_height="wrap_content"
    4.     android:button="@drawable/custom_checkbox"
    5. />
    复制代码



    以上就实现了Checkbox组件自定义,有兴趣的网友可以运行看看结果。

  • 相关阅读:
    总结随笔
    Beta冲刺第七天
    Beta冲刺第六天
    Beta冲刺第五天
    Beta冲刺第四天
    Beta冲刺第三天
    POJ 2240 Arbitrage
    POJ 3660 Cow Contest
    POJ 1797 Heavy Transportation
    LightOJ 1123 Trail Maintenance
  • 原文地址:https://www.cnblogs.com/wi100sh/p/4290622.html
Copyright © 2020-2023  润新知