ResourcesCompat和ContextCompat

getResources().getDrawable() 过时的解决方法

  • 当你这个Drawable不受主题影响时

    ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);
  • 当你这个Drawable受当前Activity主题的影响时

    ContextCompat.getDrawable(getActivity(), R.drawable.name);
  • 当你这个Drawable想使用另外一个主题样式时

    ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme)
原文地址:https://www.cnblogs.com/dubo-/p/7733117.html