Drawable tinting for api <21

后端 未结 10 1964
情话喂你
情话喂你 2020-11-29 01:56

Is it possible to make drawable tinting work for api < 21?



        
10条回答
  •  死守一世寂寞
    2020-11-29 02:35

    You can achieve that using source code. Previously tinting was not supported by DrawableCompat. Starting from support library 22.1 you can do that, but you need do it in this way:

    Drawable normalDrawable = getResources().getDrawable(R.drawable.drawable_to_tint);
    Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
    DrawableCompat.setTint(wrapDrawable, getResources().getColor(R.color.colorPrimaryLight));
    

提交回复
热议问题