Android getResources().getDrawable() deprecated API 22

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

    In Kotlin you can use extension

    fun Context.getMyDrawable(id : Int) : Drawable?{
    
        return  ContextCompat.getDrawable(this, id)
    }
    

    then use like

    context.getMyDrawable(R.drawable.my_icon)
    

提交回复
热议问题