Android中getResources().getDrawable() 過時的解決方法

轉自:http://stackoverflow.com/questions/29041027/android-getresources-getdrawable-deprecated-api-22

  1. 當你這個Drawable不受主題影響時

    ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);
  2. 當你這個Drawable受當前Activity主題的影響時

    ContextCompat.getDrawable(getActivity(), R.drawable.name);
  3. 當你這個Drawable想使用另外一個主題樣式時

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章