반응형
버튼 한번 클릭했을 때 눌린 상태로 유지되도록 합니다.
눌렸을 때랑 안 눌렸을 때를 구분하도록 selector를 만듭니다
이때 state_pressed가 아니라 state_selected를 사용한다
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/on_img" android:state_selected="true"/>
<item android:drawable="@drawable/off_img"/>
</selector>
그리고 버튼 클릭시 selected 여부를 바꿔줍니다.
button?.setOnClickListener {
button?.isSelected = button?.isSelected != true
}
반응형
'IT > Android' 카테고리의 다른 글
Android] Coroutine 재시작, 다시 호출하기 (0) | 2021.04.26 |
---|---|
Kotlin] 안드로이드 키보드 검색 (0) | 2021.03.23 |
Kotlin] 안드로이드 이미지 공유하기 // Android share image (0) | 2021.03.21 |
Kotlin] 안드로이드 레이아웃을 이미지로 변환하기 (0) | 2021.03.20 |
Kotlin] 안드로이드 뷰 확대하기, 늘리기 // Pinch zoom (0) | 2021.03.18 |
댓글