我有同樣的問題。我合併了https://stackoverflow.com/a/30928051的帖子,並嘗試了API 17,19,21,22,23和N Preview 3以及SupportLib 23.4.0來尋找解決方案。
即使有人提及,compat-class將使用前棒棒糖設備的篩選器(請參閱https://stackoverflow.com/a/27812472/2170109),它不起作用。
現在,我自己檢查API並使用以下代碼,該代碼正在處理所有測試的API(適用於17歲及以上)。使用程序兼容性支持庫API 15-25
// https://stackoverflow.com/a/30928051/2170109
Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.vector));
image.setImageDrawable(drawable);
/*
* need to use the filter | https://stackoverflow.com/a/30880522/2170109
* (even if compat should use it for pre-API21-devices | https://stackoverflow.com/a/27812472/2170109)
*/
int color = ContextCompat.getColor(context, R.color.yourcolor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
DrawableCompat.setTint(drawable, color);
} else {
drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
將發生變異() – 3xplore