以编程方式更改 Android EditText 的色调颜色

2024-01-06

我正在尝试改变一个的着色颜色EditText在运行时以编程方式查看。基本上我想改变你通常应用的内容?attr/colorControlNormal就像在默认背景可绘制 https://github.com/android/platform_frameworks_base/blob/android-wear-5.0.0_r1/core/res/res/drawable/edit_text_material.xml.

仅通过设置来更改背景色调并不能正确应用new ColorsStateList用一种颜色:

editText.setBackgroundTintList( ColorStateList.valueOf( color ) );

其一,结果适用于所有EditText尽管应用了色调列表并在内部改变了可绘制对象。还有默认背景中指定的 Alpha1 https://github.com/android/platform_frameworks_base/blob/android-wear-5.0.0_r1/core/res/res/drawable/edit_text_material.xml一开始就可见。

这是仅在第一个上设置色调颜色的结果EditText:

所以我的问题是:如何以编程方式正确地将色调应用到EditText?


这对我有用:

editText.getBackground().setColorFilter(getResources().getColor(R.color.your_color),
                                        PorterDuff.Mode.SRC_ATOP);

Source: 使用 appcompat v7 更改 EditText 底线颜色 https://stackoverflow.com/questions/26574328/changing-edittext-bottom-line-color-with-appcompat-v7

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

以编程方式更改 Android EditText 的色调颜色 的相关文章

随机推荐