[안드로이드] resources.getDrawable() 메서드의 deprecated 문제 대응

thsamajiki·2023년 8월 9일
0

트러블슈팅

목록 보기
3/25

resources.getDrawable() 메소드의 deprecated 대응

  • resources.getDrawable(id: Int) 메서드는 API 22에서 deprecated 되었습니다.
  • resources.getDrawable(id: Int) 메서드 대신에 resources.getDrawable(id: Int, theme: Theme)를 사용하기보다는 ContextCompat.getDrawable(Context context, int id) 메소드로 대체해서 사용하는 게 좋다.



getDrawable() 원형

ContextCompat(android.support.v4.content.ContextCompat) 클래스에 있는 getDrawable() 메서드를 사용한다.

binding.textLayout.background = ContextCompat.getDrawable(this, R.drawable.border_text_input_layout_selected)



실제 호출방법

ContextCompat.getDrawable(context, id);

profile
안드로이드 개발자

0개의 댓글