How to set border color for EditText

戏子无情 提交于 2019-12-10 16:17:33

问题


I have used this.

<color name="edt_pressed">#99CBFF</color>
<color name="edt_focused">#CEF7F6</color>
<color name="edt_default">#000000</color>

gradient_edt_focused

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">    
<stroke android:width="1dip" android:color="@color/edt_focused" />
</shape>

edt_border.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_pressed="true" android:drawable="@layout/gradient_edt_pressed"/>
<item android:state_focused="true" android:drawable="@layout/gradient_edt_focused"/>
<item android:drawable="@layout/gradient_edt_default"/>
</selector>

activity_main.xml

<EditText
    android:id="@+id/uname" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"                
    android:singleLine="true"
    android:background="@layout/textview_border"/>

Now the border is working fine but while typing text, that has the background color of black.


回答1:


The issue is it is taking the color of the default item as background while onfocus as I did not gave any solid color for each. So now i added this in "gradient_edt_focused".

<solid android:color="#00000000" />

Now it is working.



来源:https://stackoverflow.com/questions/16976888/how-to-set-border-color-for-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!