突出显示EditText文本颜色

时间:2013-07-30 03:55:42

标签: android xml android-edittext android-selector

如何在突出显示时更改文字的颜色?这是我尝试过的:

edittext_text_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="#FFFFFF"/>
    <item android:state_selected="false" android:color="@color/custom_blue"/>

</selector>

some_layout.xml

<org.holoeverywhere.widget.EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_margin="5dp"
    android:background="@android:drawable/editbox_background_normal"
    android:ems="10"
    android:gravity="right"
    android:inputType="textPersonName"
    android:textColor="@drawable/edittext_text_color"
    android:textCursorDrawable="@null">

正常状态

enter image description here

突出显示状态

enter image description here

突出显示文字时我想要的是

enter image description here

1 个答案:

答案 0 :(得分:2)

我不认为这是支持的。从我在source code中看到的情况来看,突出显示的文本没有单独的属性,仅适用于突出显示的背景。仅使用文本颜色状态绘制文本,突出显示或不突出显示。

此外,android:state_selected="true"代表ColorState的{​​{1}},而不代表其中的文字。

相关问题