android - 如何为EditText设置边框颜色

标签 android android-edittext border-color

我用过这个。

<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"/>

现在边框工作正常,但在键入文本时,背景颜色为黑色。

最佳答案

问题是它在 onfocus 时将默认项目的颜色作为背景,因为我没有为每个项目提供任何纯色。所以现在我在“gradient_edt_focused”中添加了它。

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

现在它正在工作。

关于android - 如何为EditText设置边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16976888/

相关文章:

java - 使用唯一的字符串设置默认适配器

java - Java 数组中每个元素有多个值

android:从MultiAutoComplete Textview中获取所选项目并进行更新并更新EditView?

android - 如何为android添加语言支持

android - 为什么objectAnimator不调用setter方法

css - 如何使用 CSS 制作透明边框?

objective-c - 更改 NSTextField 的边框颜色

CSS 类不会覆盖边框样式

android - 将edittext限制为单行

Android Edittext 富文本格式