getResources().getDrawable() is deprecated

Posted by phantomVK on May 16, 2018

方案A (推荐):

获取带主题属性的drawable,主题配置来自当前Activity:

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

方案B:

获取不带主题属性的drawable:

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

方案C:

获取带自定义主题属性的drawable:

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