2016-05-17 149 views
1

我正在創建一個應用程序,它有edittext的幾個變化,當edittext有焦點或沒有焦點時。當視圖具有焦點的顏色應該是藍色的,正常的時候就應該有白色,像這樣:風格EditText下劃線顏色android

enter image description here

我試圖根據這個XML,但創建二九補丁和設置背景似乎不起作用。任何人都可以告訴我如何實現這一目標?

的Xml選擇:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="true" android:state_focused="true" 
     android:drawable="@drawable/spelling_blue" /> 
    <item android:state_window_focused="false" android:state_enabled="true" 
     android:drawable="@drawable/spelling_white" /> 
    <item android:drawable="@drawable/spelling_white" /> 
</selector> 

感謝

+0

試試這個http://stackoverflow.com/questions/35262935/android-edittext-bottom-line-color-and-theme-changes/35263829#35263829希望這將有助於您。 –

+0

你有什麼資源?你能顯示spelling_blue和spelling_white嗎? – manao

+1

嘗試到 <?xml version =「1.0」encoding =「utf-8」?> Alexander

回答

0

我不認爲你需要使用android:state_window_focused

試試這個:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_pressed="true" 
     android:drawable="@drawable/spelling_blue" /> <!-- pressed -->  
    <item 
     android:state_focused="true" 
     android:drawable="@drawable/spelling_blue" /> <!-- focused -->  
    <item 
     android:drawable="@drawable/spelling_white" /> <!-- default --> 
</selector> 
相關問題