我想在Edittext中更改下划线的颜色,并按照一些教程来执行此操作。
我创建了这个xml文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#00FFFFFF" />
<padding android:bottom="2dp" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
但是我只做下划线而不是所有的矩形,类似于默认线,但是在蓝色和纯色背景交会中是白色的。
我该怎么做?
由于
答案 0 :(得分:5)
您也可以以编程方式更改它:
public static void changeEditTextUnderlineColor(EditText editText) {
int color = Color.parse("#[putColorHere]")
Drawable drawable = editText.getBackground();
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
editText.setBackground(drawable);
} else {
editText.setCompoundDrawables(null, null, drawable, null);
}
}
答案 1 :(得分:2)
您可以在styles.xml中指定 EditText 中更改编辑颜色下划线。在您的应用主题 styles.xml 中添加以下内容。
<item name="android:textColorSecondary">@color/primary_text_color</item>