Android getDrawable过时的替代方法

之前代码中获取Drawable都是使用如下方法:
Drawable TopDrawableOne = getResources().getDrawable(R.drawable.icon_test);

但是此方法过时,不推荐使用,那么肯定是有其他替代方法的,经过查找,很多网友都是推荐使用
Drawable getDrawable(int id, Resources.Theme theme), 第二个参数@theme可以为空值.或Context.getDrawable(int)

但是感觉此方法不是很好用就在此查找有没有其他好用的方法,最后找到
 Drawable TopDrawableOne = ContextCompat.getDrawable(context,R.drawable.icon_test);
这种方式,看着舒服,也是谷歌推荐使用的

发布了64 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/GracefulGuigui/article/details/103728011