gpt4 book ai didi

android - 如何删除 EditText 的色调颜色或将其设置为 android 中的默认样式?

转载 作者:行者123 更新时间:2023-11-29 15:08:25 25 4
gpt4 key购买 nike

我在样式中的默认色调强调颜色是蓝色,并且在错误发生时我将它以编程方式更改为红色,如下面的代码

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

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

最佳答案

对于您的情况,更喜欢使用 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();

关于android - 如何删除 EditText 的色调颜色或将其设置为 android 中的默认样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34505169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com