【问题标题】:Edit color of underline in Edittext Android在 Edittext Android 中编辑下划线的颜色
【发布时间】:2014-09-30 09:11:34
【问题描述】:

我想改变 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>

但我只做下划线,而不是所有矩形,类似于默认线,但在蓝色和纯色背景 transpartet 内部是白色的。

我该怎么做?

谢谢

【问题讨论】:

标签: java android android-edittext


【解决方案1】:

您也可以通过编程方式更改它:

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

【讨论】:

  • 你也可以创建statelist drawables并把它放在那里
  • 如何以编程方式改变文本选择指针的颜色?
【解决方案2】:

您可以在EditText 中更改编辑颜色下划线,并在styles.xml 中指定它。在您的应用主题 styles.xml 中添加以下内容。

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

【讨论】:

  • 为我工作。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 2017-07-23
  • 2018-08-13
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 2011-12-02
相关资源
最近更新 更多