我正在尝试编写一个可以更改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"/>
<style name="BusinessColor" parent="DefaultColor">
<item name="android:fillColor">@color/brown_piana</item>
</style>
BitmapDescriptor icon = new BitMapConverter().getBusinessBitmap(context, R.drawable.ic_map_marker_scooter);
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。现在没有图标显示,为空。
如果需要的话,我会提供其他信息,请帮助我解决此问题。