Why getDrawable() doesn't work on some Android devices?

元气小坏坏 提交于 2019-12-03 04:38:11

I'm going to bet it is failing on getDrawable(R.drawable.rblack, getTheme()); which was added in API 21. Change that line to:

if(android.os.Build.VERSION.SDK_INT >= 21){
    rBlack = getResources().getDrawable(R.drawable.rblack, getTheme());
} else {
    rBlack = getResources().getDrawable(R.drawable.rblack);
}
Gor
ContextCompat.getDrawable(Context context, int id)
user3296448

Try adding the following line of code:

context.getResources().getDrawable(R.drawable.your_image_name);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!