我想基本上创建API 21+ tintxml属性的"支持"版本.如何tint在代码中从drawable 获取属性(或自定义属性),而不View对每个图像使用自定义?
这是/res/drawable/brandable_icon_slider_featured.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tintns="http://schemas.android.com/apk/res-auto"
android:src="@drawable/brandable_icon_slider_featured_img"
tintns:tintColor="@color/branded_menu" />
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个自定义Resources子类并在我的活动中使用它.
public class CustomResource extends Resources {
...
@Override
public XmlResourceParser getXml(int id) throws NotFoundException {
XmlResourceParser parser = super.getXml(id);
return parser;
}
@Override
public Drawable getDrawableForDensity(int id, int density) throws NotFoundException {
return replaceWithTintableBitmap(super.getDrawableForDensity(id, density));
}
@Override
public Drawable getDrawableForDensity(int id, int density, Theme theme) {
return replaceWithTintableBitmap(super.getDrawableForDensity(id, density, theme));
}
@Override
public Drawable getDrawable(int id) throws NotFoundException …Run Code Online (Sandbox Code Playgroud)