1

My default tint Accent color in styles is blue and on error occur im changing it to red programmatically like below code

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

But when i restart my app the tint color is red , How do i set it back to default color which is in style.xml ?

Uday
  • 1,619
  • 3
  • 23
  • 48

2 Answers2

4

Prefer use colorFilter and not tintcolor for your case :

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

To remove the filter color, just use clearColorFilter :

wrappedDrawable.clearColorFilter();
Kevin ABRIOUX
  • 16,507
  • 12
  • 93
  • 99
1

this work for me

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

Changing EditText bottom line color with appcompat v7

Community
  • 1
  • 1
Däñish Shärmà
  • 2,891
  • 2
  • 25
  • 43
  • How do i reset it back to default color which is in style.xml. the problem here is when i restart the app, the bottum line will be always red. I want it to be default color. – Uday Dec 29 '15 at 06:17