基本上,我试图将一个SVG drawable添加到ImageView中,但我不断遇到我无法解决的奇怪类型错误。
// String var "icon" holds the name of the drawable resource
int drawableId = context.getResources()
.getIdentifier(icon, "drawable", MainActivity.PACKAGE_NAME);
// drawableId shows the error:
// 'getDrawable(android.content.Context, int)' in 'android.support.v4.content.ContextCompat' cannot be applied to '(int)'
// I tried using Context instead of ContextCompat, but I got an error about needing API 21
Drawable channelIcon = ContextCompat.getDrawable(drawableId);
// drawableId here shows no error
imageView.setImageResource(drawableId);
知道我做错了什么吗?基本上这是需要使用R.drawable.something
感谢。
答案 0 :(得分:1)
我试图将SVG drawable添加到ImageView
ImageView
不支持SVG。
知道我做错了吗?
除了上述问题,请替换:
Drawable channelIcon = ContextCompat.getDrawable(drawableId);
使用:
Drawable channelIcon = ContextCompat.getDrawable(context, drawableId);