2016-07-25 53 views
2

我有編輯的文字是這樣的:安卓EDITTEXT改變背景顏色,當輸入

<EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:hint="input something" 
      android:layout_weight="1" 
      android:textSize="20sp" 
      android:textColor="#04ff00" 
      android:textColorHint="#0094fd"/> 

這是結果:

enter image description here

一樣的形象,我想改變文本時的背景在edittext中輸入。
該怎麼辦?

+0

只是可以肯定,要更改所選文本的背景顏色,對? –

+0

是的,我的意思是。 – 1234abcd

回答

1

爲了實現這一行爲添加textColorHighlightEditText

<EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:hint="input something" 
     android:layout_weight="1" 
     android:textSize="20sp" 
     android:textColor="#04ff00" 
     android:textColorHint="#0094fd" 
     android:textColorHighlight="@android:color/holo_red_light"/> 

最後的結果是這樣的: enter image description here

+0

我試過,在genymotion中,它沒事。但是當在真實設備上測試使用android 5.0.2時,它不是那樣的。 – 1234abcd

+0

嗯,我用Android M檢查了我的Nexus 5x,它看起來不錯...你可以提供更多的細節,或者嘗試一個乾淨的構建? –

+0

哦,只是我的錯。對於那個很抱歉。非常感謝 – 1234abcd