CheckedTextView,CheckBox和Button样式定义

1.改变CheckBox的默认样式,

由方形变成自定义的形状,具体步骤如下:

a> 定义drawable.xml文件,指定CheckBox的button 属性,

drawable.xml如下所示“:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:state_focused="true"

          android:drawable="@drawable/checkbox_on" />

    <item android:state_checked="false" android:state_focused="true"

          android:drawable="@drawable/checkbox_off" />

    <item android:state_checked="false"

          android:drawable="@drawable/checkbox_off" />

    <item android:state_checked="true"

          android:drawable="@drawable/checkbox_on" />

</selector>

在使用CheckBox的xml布局文件里,使用属性button指定刚才的drawable.xml,

<CheckBox
                android:id="@+id/checkbox"
                android:layout_width="wrap_content"
                android:button="@drawable/checkbox"
                android:layout_gravity="center"
                android:gravity="center"

                android:layout_centerInParent="true"
                android:layout_height="match_parent"
        />

效果如下:


2.改变Button的样式:

a>改变Button的按下按上效果:

定义drawable.xml文件,设定按下和按上的效果,

<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:drawable="@drawable/btn_cancel_pressed_1margin" android:state_pressed="true"
     />
    <item android:drawable="@drawable/btn_cancel_normal_1margin"/>
</selector>


然后指定Button的background属性即可

b>改变Button 按下和按上时的字体颜色

定义drawable.xml,设定按下和按上时的字体颜色,如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@color/white"/>
    <item android:state_focused="true" android:color="@color/white"/>
    <item android:color="@color/common_orange" />
</selector>

然后指定Button的textColor 属性

完整代码:

       <Button android:layout_width="@dimen/intro_post_130"
                android:layout_height="@dimen/intro_margin_40"
                android:textSize="@dimen/intro_margin_15"
                style="@style/dialog_btn_cancel"
                android:id="@+id/btn_cancel_mile"
                android:textColor="@drawable/button_font_style"
                android:layout_margin="@dimen/intro_margin_10"
                android:layout_centerVertical="true"
                android:background="@drawable/btn_cancel_1margin"
                android:text="@string/button_cancel"
        />


3.改变CheckedTextView的样式更改

a> 定义drawable.xml文件,和CheckBox指定的button 属性文件一样

b>在代码中设置:

            checkedTextView.setCheckMarkDrawable(R.drawable.checkbox_selector_drawable);



总结:该文没有什么实质性的东西,只是作为一个整理,勿见怪!!



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值