在AndroidStudio中更改SVG可绘制对象的一种颜色

时间:2019-10-23 06:08:47

标签: java windows android-studio svg colors

我正在尝试编写一个可以更改SVG文件特定颜色的函数。它是一种向量资产,所以它是一个XML文件:我认为这样做会使事情变得简单,但事实并非如此。

ColorFilter对我没有做任何事情,因为那只是一个过滤器。我想更改传递对象本身的特定颜色,以便将其传递给另一个函数,该函数会将其转换为BitmapDescriptor。

更改颜色的功能

private Drawable changeColor(Drawable mydrawable, Context context) {
        ContextThemeWrapper wrapper = new ContextThemeWrapper(context, R.style.BusinessColor);
        mydrawable.applyTheme(wrapper.getTheme());
        return mydrawable;
}

我要更改的可绘制部分

 <path
      android:pathData="path_data"
      android:fillColor="@color/scooter_green"/>

将更改颜色的styles.xml参考

   <style name="BusinessColor" parent="DefaultColor">
        <item name="android:fillColor">@color/brown_piana</item>
    </style>

HomeActivity用法

 BitmapDescriptor icon = new BitMapConverter().getBusinessBitmap(context, R.drawable.ic_map_marker_scooter);

Getbusinessbitmap

public BitmapDescriptor getBusinessBitmap(Context context, int drawableId) {
        Drawable drawable = ContextCompat.getDrawable(context, drawableId);
        Drawable business = changeColor(drawable, context);
        return getBitmap(business);

由于对象的标准颜色是scooter_green,因此我想在HomeActivity中决定何时将该对象的颜色更改为piana_brown。现在没有图标显示,为空。

如果需要的话,我会提供其他信息,请帮助我解决此问题。

0 个答案:

没有答案
相关问题