Android getResources().getDrawable() deprecated API 22

后端 未结 14 1893
隐瞒了意图╮
隐瞒了意图╮ 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:09

    Replace this line : getResources().getDrawable(R.drawable.your_drawable)

    with ResourcesCompat.getDrawable(getResources(), R.drawable.your_drawable, null)

    EDIT

    ResourcesCompat is also deprecated now. But you can use this:

    ContextCompat.getDrawable(this, R.drawable.your_drawable) (Here this is the context)

    for more details follow this link: ContextCompat

提交回复
热议问题