Android 如何为EditText设置边框颜色
我用过这个Android 如何为EditText设置边框颜色,android,android-edittext,border-color,Android,Android Edittext,Border Color,我用过这个 <color name="edt_pressed">#99CBFF</color> <color name="edt_focused">#CEF7F6</color> <color name="edt_default">#000000</color> #99CBFF #CEF7F6 #000000 梯度edt聚焦 <?xml version="1.0" encoding="utf-8"?> <
<color name="edt_pressed">#99CBFF</color>
<color name="edt_focused">#CEF7F6</color>
<color name="edt_default">#000000</color>
#99CBFF
#CEF7F6
#000000
梯度edt聚焦
<?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>
<EditText
android:id="@+id/uname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:background="@layout/textview_border"/>
活动\u main.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>
<EditText
android:id="@+id/uname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:background="@layout/textview_border"/>
现在,边框工作正常,但在键入文本时,背景颜色为黑色。问题是,它在聚焦时将默认项的颜色作为背景,因为我没有为每个项提供任何纯色。现在我在“梯度edt聚焦”中添加了这个
现在它正在工作。我想您需要在selectorSorry中设置状态\u selected..我发现了问题。它是在对焦时以第三个项目的颜色作为背景。所以现在我加入了“梯度edt聚焦”,它开始工作了。