Android TextView 동적으로 Background 색상 변경하기

98oys·2022년 11월 10일
0

안드로이드

목록 보기
19/20

RecyclerView의 item마다 Background 색상을 동적으로 변경하기 위해 아래와 같은 방법을 사용하였습니다.


setBackgroundTinitList는 매개변수로 ColorStateList를 받기 때문에

                val states = arrayOf(intArrayOf(android.R.attr.state_enabled))
                val colors = intArrayOf(Color.parseColor(item.iconColor))
                val colorStateList = ColorStateList(states, colors)
                
                circleIconColor.backgroundTintList = colorStateList

ColorStateList 객체를 만들었습니다!

출처 : https://stackoverflow.com/questions/44083225/how-to-set-appbackgroundtint-for-textview-programatically

profile
Android Developer, Department of Information and Communication Engineering, Inha University

0개의 댓글