Change fillColor of a vector in android programmatically

后端 未结 5 2277
情书的邮戳
情书的邮戳 2020-12-15 03:13

I want to edit the fill Color of a vector-file in Android programmatically.

In the xml-file I can set my color with the attribute android:fillColor

5条回答
  •  [愿得一人]
    2020-12-15 03:33

    If you want to change the whole color, you could apply a PorterduffColorFilter. But this does not work for a single . Only for the whole drawable.

    public void applyThemeToDrawable(Drawable image) {
        if (image != null) {
            PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(Color.BLUE,
                    PorterDuff.Mode.SRC_ATOP);
    
            image.setColorFilter(porterDuffColorFilter);
        }
    }
    

    VectorDrawable extends the Drawable class. See Docs

提交回复
热议问题