textview中点击效果实现,比如点击textview中实现图片和文字的颜色变化(类似于button)

<TextView
    android:drawableTop="@drawable/bg_text_view"
    android:id="@+id/home_toolbar_settings"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:gravity="center"
    android:text="@string/home_toolbar_settings"
    android:textColor="@color/text_view_color"
    android:textSize="12sp"

/>

样式:

1.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:drawable="@drawable/setting_on" />          <!--点击后的图片-->
    <item android:state_focused="true" android:drawable="@drawable/setting_on" />
    <item android:drawable="@drawable/setting_off" />      <!--点击前的图片-->
 </selector>

2.在res文件夹中新建color文件夹,然后在里面新建.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">                 <!--点击后的颜色-->
    <item android:state_selected="true" android:color="@color/color_409fff" />
    <item android:state_focused="true" android:color="@color/color_409fff" />
    <item android:state_pressed="true" android:color="@color/color_409fff" />
    <item android:color="@color/color_666666" />    <!--点击前的颜色-->
</selector>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值