Changing tint color of Android EditText programmatically

后端 未结 5 651
孤城傲影
孤城傲影 2021-02-03 22:07

I am trying to change the tinting color of an EditText View programmatically during runtime. Basically i want to change what you would usually apply as ?attr/

5条回答
  •  醉梦人生
    2021-02-03 22:50

    setColorFilter not working for me. I used:

    Drawable wrappedDrawable = DrawableCompat.wrap(mView.getBackground());
    DrawableCompat.setTint(wrappedDrawable, getResources().getColor(R.color.red));
    mView.setBackgroundDrawable(wrappedDrawable);
    

    or

    DrawableCompat.setTint(mView.getBackground(), ContextCompat.getColor(this, R.color.red));
    

    Let's try.

提交回复
热议问题