일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 애드몹광고
- 안드로이드컴포즈
- 애드몹배너
- android daum map
- android 지도
- 안드로이드
- 컴포넌트
- JetpackCompose
- 안드로이드 카카오 지도
- Android
- android kakao map
- 클린 아키텍처
- Clean Architecture
- Android 애드몹
- 선언형UI
- 다이나믹 링크
- 젯팩컴포즈
- thread
- HTTP
- 동적 링크
- component
- dynamiclink
- 안드로이드광고
- glide
- 아키텍처
- ImageView
- Firebase
- 파이어베이스
- 안드로이드 라이브러리
- RecyclerView
- Today
- Total
코딩스토리
[Android/안드로이드] Button Select Event - 버튼 눌림 효과 본문
버튼을 클릭했을 때 버튼이 눌릴 때 색이 변한다던가, 이미지가 변하는 경우가 있습니다.
색이 변하기 위해서는 먼저 res폴더 안에 drawable에 파일을 추가해줘야 합니다.
파일을 생성하게 되면 코드를 작성합니다. 저는 "button_back.xml"이라고 생성했습니다.
button_back.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape>
<solid android:color="#000"/>
<corners
android:radius="5sp"/>
</shape>
</item>
<item android:state_pressed="true" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#999"/>
<corners
android:radius="5sp"/>
</shape>
</item>
</selector>
버튼을 생성해 줄때 background속성에 방금 만든 button_back을 넣어줍니다.
<Button
android:id="@+id/btn1"
android:background="@drawable/button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
selector xml의 이벤트는 다음과 같은 속성을 주로 사용합니다.
android:state_pressed = 객체를 누를 때 (ex : 버튼을 터치하거나 클릭 할 때)이 항목을 사용해야하는 경우 "true"; 이 항목을 누르지 않은 기본 상태로 사용해야하는 경우 "false"입니다.
android:state_checked = 개체를 확인할 때 이 항목을 사용해야하는 경우 "true"입니다. 객체를 체크하지 않은 상태에서 사용해야하는 경우 "false"입니다.
android:state_enabled = 개체가 활성화되어있을 때이 항목을 사용해야하는 경우 "true"(터치 / 클릭 이벤트 수신 가능); 개체를 사용할 수 없을 때 사용해야하는 경우 "false"입니다.
android:state_focused = 버튼이 강조 표시 될 때와 같이 객체에 포커스가있을 때이 항목을 사용해야하는 경우"true "; 이 항목을 초점이없는 기본 상태로 사용해야하는 경우 "false"입니다.
android:state_selected = 개체를 선택할 때 (ex : 탭을 열 때와 같이)이 항목을 사용해야하는 경우 "true"; 개체를 선택하지 않은 상태에서이 항목을 사용해야하는 경우 "false"입니다.
'Android > 유용한 기술' 카테고리의 다른 글
[Android/안드로이드] 패키지명 한번에 변경하는 방법 (0) | 2020.07.30 |
---|---|
[Android/안드로이드] BlurView를 사용해 블러효과 주기 (2) | 2020.07.09 |
[Android/안드로이드] 1초 후 실행 - postDelayed (0) | 2020.05.04 |
[Android/안드로이드] 카카오톡 로그인 (v2 ‘사용자 정보 요청’ API로 업데이트) (6) | 2020.04.15 |
[Android/안드로이드] RecyclerView 상단 하단 padding (android:clipToPadding ) (0) | 2020.04.13 |