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

最近在使用这个方法的时候总是在网上搜,感觉很麻烦,所以在这里记忆一下。

  1. 当你这个Drawable不受主题影响时
ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);
  1. 当你这个Drawable受当前Activity主题的影响时
ContextCompat.getDrawable(getActivity(), R.drawable.name);
  1. 当你这个Drawable想使用另外一个主题样式时
ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme);
    原文作者:码农仔
    原文地址: https://www.jianshu.com/p/21558fe8b750
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞