Is it possible to change material design icon color from xml in Android?

前端 未结 9 1060
囚心锁ツ
囚心锁ツ 2020-12-05 06:39

I\'m actually trying to use colored icons in my app. I\'ve downloaded the official material design icon pack from here. Now all the icons in this pack are either white, grey

9条回答
  •  [愿得一人]
    2020-12-05 07:25

    Many alternatives here already in this thread. Perhaps I can add one more for whoever finds it convenient :

    You can also use the Drawable class, the code being as follows

        Resources res = getResources();
        Drawable drawable = res.getDrawable(R.drawable.ic_play_circle_filled);
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, getResources().getColor(R.color.colorPrimary));
    

    Although the above did the trick for me, but for my use case suggicient was to use android:tint

提交回复
热议问题