2016-05-17 120 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>