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

2020-10-29  本文已影响0人  谁动了我的代码QAQ

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);
上一篇 下一篇

猜你喜欢

热点阅读