美文网首页
Android getResources() 方法过时的替代方法

Android getResources() 方法过时的替代方法

作者: 谁动了我的代码QAQ | 来源:发表于2020-10-29 11:02 被阅读0次

1.getResources().getColor()方法过时

ContextCompat.getColor(context, R.color.black); 

2.getResources().getDrawable()方法过时

(1).使用drawable资源但不为其设置theme主题

ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);

(2).使用默认的activity主题

ContextCompat.getDrawable(getActivity(), R.drawable.name);

(3).使用自定义主题

ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme);

相关文章

网友评论

      本文标题:Android getResources() 方法过时的替代方法

      本文链接:https://www.haomeiwen.com/subject/uddkvktx.html