如何更改文本颜色在一个特定的TextView的preSS中的LinearLayout如何更改、文本、颜色、LinearLayout

由网友(心事死在風裏)分享简介:我有一个线性布局3文本视图。我要的是选择任何文本视图时,更改文本视图的字体颜色。我想,直到另一个文本视图中选择保留新的颜色。基本上这个线性布局应模仿复选框的选择行为。我想使用选择更改文本视图的字体颜色的颜色。 I have a Linear layout with 3 text views. I want to ch...

我有一个线性布局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);
阅读全文

相关推荐

最新文章