Android getResources().getDrawable() deprecated API 22

后端 未结 14 2118
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 07:14

With new android API 22 getResources().getDrawable() is now deprecated. Now the best approach is to use only getDrawable().

What changed? <

14条回答
  •  再見小時候
    2020-11-22 08:05

    Now you need to implement like this

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //>= API 21
            //
        } else {
            //
        }
    

    Following single line of code is enough, everything will take care by ContextCompat.getDrawable

    ContextCompat.getDrawable(this, R.drawable.your_drawable_file)
    

提交回复
热议问题