2013-07-30 131 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'繪製的所有內容的頂部)。 –

相關問題