简体   繁体   English

在Edittext Android中编辑下划线的颜色

[英]Edit color of underline in Edittext Android

I want to change color of underline in Edittext and i follow some tutorials to do this. 我想在Edittext中更改下划线的颜色,并按照一些教程进行操作。

I create this xml file: 我创建此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>

But i only do the underline not all rectangle, similiar as default line but white inside of blue and solid background transpartet. 但是我只做下划线,而不是所有矩形,都与默认线类似,而是在蓝色和纯色背景透明的内部白色。

How can i do this? 我怎样才能做到这一点?

Thanks 谢谢

You can change it programatically too: 您也可以通过编程方式更改它:

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);
    }
}

you can change Edit color Underline in EditText specifying it in styles.xml. 您可以在styles.xml中将其指定为EditText的下划线更改为下划线。 In your app theme styles.xml add the following. 在您的应用程序主题styles.xml中添加以下内容。

<item name="android:textColorSecondary">@color/primary_text_color</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM