【问题标题】:How to remove the tint color of EditText or set it to default style in android?如何删除 EditText 的色调颜色或将其设置为 android 中的默认样式?
【发布时间】:2023-04-04 22:00:01
【问题描述】:

我在样式中的默认色调重音颜色是蓝色,如果发生错误,我会像下面的代码一样以编程方式将其更改为红色

    Drawable wrappedDrawable = DrawableCompat.wrap(mUsername.getBackground());
    DrawableCompat.setTint(wrappedDrawable, ContextCompat.getColor(getActivity(), R.color.red_error));

但是当我重新启动我的应用程序时,色调颜色为红色,我如何将其设置回 style.xml 中的默认颜色?

【问题讨论】:

标签: android android-edittext material-design textinputlayout


【解决方案1】:

对于您的情况,更喜欢使用 colorFilter 而不是 tintcolor :

//get reference on drawable
Drawable wrappedDrawable = DrawableCompat.wrap(mUsername.getBackground());
//get color ressource with Android M SDK
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    wrappedDrawable.setColorFilter(this.getColor(R.color.blue), PorterDuff.Mode.MULTIPLY);
else
    //classic method
    wrappedDrawable.setColorFilter(this.getResources().getColor(R.color.blue), PorterDuff.Mode.MULTIPLY);

要删除过滤器颜色,只需使用 clearColorFilter :

wrappedDrawable.clearColorFilter();

【讨论】:

    【解决方案2】:

    这对我有用

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

    Changing EditText bottom line color with appcompat v7

    【讨论】:

    • 如何将其重置为 style.xml 中的默认颜色。这里的问题是当我重新启动应用程序时,底部线将始终为红色。我希望它是默认颜色。
    猜你喜欢
    • 2017-11-11
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多