2013-07-30 133 views
2

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

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

+0

改变一些颜色,看看会发生什么。 并看到这一个http://developer.android.com/resources/articles/touch-mode.html可能会有所帮助 –

+0

http://developer.android.com/guide/topics/resources/color-list-resource.html检查这一个可能它会帮助你 –

+0

@PratikButani我玩过很多颜色,但没有帮助。 –

回答

2

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

此外,android:state_selected="true"代表ViewColorState,而不是其中的文本。

+0

如何观察高亮状态并动态改变颜色? –

+0

@ Eng.Fouad你可以重写'TextView'的onDraw()',找到高亮文本的坐标并用不同的颜色重新绘制该文本(在'TextView'绘制的所有内容的顶部)。 –

相关问题