簡體   English   中英

如何在Android中刪除EditText的色調顏色或將其設置為默認樣式?

[英]How to remove the tint color of EditText or set it to default style in android?

我在樣式中的默認色調強調顏色為藍色,並且在發生錯誤時,通過編程方式將其更改為紅色,如以下代碼所示

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

這項工作對我來說

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

使用appcompat v7更改EditText底線顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM