如何更改文本颜色在一个特定的TextView的preSS中的LinearLayout [英] How to change text color on press of a particular textview in a linearlayout

查看:178
本文介绍了如何更改文本颜色在一个特定的TextView的preSS中的LinearLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个线性布局3文本视图。我要的是选择任何文本视图时,更改文本视图的字体颜色。我想,直到另一个文本视图中选择保留新的颜色。基本上这个线性布局应模仿复选框的选择行为。我想使用选择更改文本视图的字体颜色的颜色。

I have a Linear layout with 3 text views. I want to change the text view's font color when any of the text view is selected. I would like to retain the new color until another text view is selected. Basically this linear layout should mimic check box's selection behavior. I would like to use the selector to change the color of the text view's font color.

我用文本视图的文字​​颜色下面的选择也只有这一点,只要文本视图是pressed

I used the below selector on text view's textColor and this only changes the font color as long as the text view is pressed

 android:textColor="@drawable/selector_header_text"

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/blue"></item>
    <item android:state_focused="true" android:color="@color/blue"/>
    <item android:color="@color/light_gray"></item>

</selector>

我怎样才能使线性布局我的文字的观点,只要保留文本颜色作为其选择,而不仅仅是pressed?

How can I make my text views in linear layout to retain text color as long as its selected and not just pressed ?

推荐答案

添加code 的android:state_selected =真正的您选择文件

add the code android:state_selected="true" to your selector file

<?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/blue"></item>
    <item android:state_focused="true" android:color="@color/blue"/>
    <item android:state_selected="true" android:color="@color/blue"/>
    <item android:color="@color/light_gray"></item>

</selector>

在你的类文件中添加以下code,

In your class file add the following code,

textView.setselected(true);

这篇关于如何更改文本颜色在一个特定的TextView的preSS中的LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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