android 改变文字颜色,点击切换不同的颜色


先看效果:

                   


为了达到界面效果,试了半天,

<----------------------------------------------------------->

通过点击切换文字颜色:

1.

在color中设置你要用到的颜色:

<resources>

    <drawable name="compare_data_text1">#FFFFFF
</drawable>
    <drawable name="compare_data_text2">#FF4B4A</drawable>

</resources>

注意:在定义颜色时必须为drawable的属性:

2.

书写selector来判断效果需要什么颜色:

textcolor_selector


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

    <item android:state_checked="false" android:color="@drawable/compare_data_text1"/>
    <item android:state_checked="true" android:color="@drawable/compare_data_text2"/>
</selector>

3在要用到的位置添加text_selector。

 <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checkedButton="@+id/day_radio"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/day_radio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/marign_distance"
            android:layout_weight="1"
            android:background="@drawable/compare_border_selector"
               android:textColor="@drawable/textcolor_selector"
            android:button="@null"
            android:gravity="center"
            android:text="日"
            />

        <RadioButton
            android:id="@+id/moth_radio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/marign_distance"
            android:layout_weight="1"
            android:background="@drawable/compare_border_selector"
            android:button="@null"
            android:gravity="center"
            android:textColor="@drawable/textcolor_selector"
            android:text="月"
        />

   </RadioGroup>

<-------------------------------------------OK------------------------------------------------>

也不知道是问什么,有知道原理的还希望告诉我,谢谢!



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值