如何改变文本的颜色TextView的悬停像在CSS? [英] How to change color of the text in TextView on hover like in css?

查看:452
本文介绍了如何改变文本的颜色TextView的悬停像在CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变文本的颜色TextView的悬停像在CSS与选择?我知道按钮定义选择与项目

How to change color of the text in TextView on hover like in css with selector? I know for button to define selector with items

<item
    android:drawable="@drawable/down"
    android:state_pressed="true"
    android:state_enabled="true">
</item>
<item
    android:drawable="@drawable/up"
    android:state_focused="true"
    android:state_enabled="true">
</item>

但我需要TextView的文字颜色,但项目无法识别该属性。有没有办法从XML,而不是从code做到这一点 ?

but I need for TextView textColor, but item doesn't recognize that attribute. Is there way to do this from xml and not from code ?

推荐答案

补充一下,选择一个资源文件( RES /彩色/ text_color.xml

Add that selector as a resource file (res/color/text_color.xml)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@color/focused_text_color"/>
    <item android:state_pressed="true" android:state_enabled="false" android:color="@color/pressed_text_color" />
    <item android:state_enabled="false" android:color="@color/disabled_text_color" />
    <item android:color="@color/default_text_color"/>
</selector>

和使用它:

android:textColor="@color/text_color"

这篇关于如何改变文本的颜色TextView的悬停像在CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆