반응형
ListView에서 selector를 설정하는 메소드는 AbsListView에 구현되어 있습니다.
메소드의 이름은 setSelector() 이고, 사용방법은 API 문서를 보시기 바랍니다.
안드로이드에서 selector의 xml파일은 list_selector_background.xml 입니다.
selector는 Drawable를 상속받아 구현된 StateListDrawable 객체입니다.
selector는 6가지의 상태에 대해서 동작하도록 되어있습니다.
@color/transparent은 ColorDrawable 타입이고,
@drawable/list_selector_background_transition은 TransitionDrawable로 되어있고,
@drawable/list_selector_background_disabled과 @drawable/list_selector_background_focus은 NinePatchDrawable 타입으로 되어있습니다.
자신만의 selector를 만들 경우, 위의 xml의 구조를 따라 만들면, 쉽게 만들 수가 있습니다.
메소드의 이름은 setSelector() 이고, 사용방법은 API 문서를 보시기 바랍니다.
안드로이드에서 selector의 xml파일은 list_selector_background.xml 입니다.
selector는 Drawable를 상속받아 구현된 StateListDrawable 객체입니다.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"
android:drawable="@drawable/list_selector_background_focus" />
</selector>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"
android:drawable="@drawable/list_selector_background_focus" />
</selector>
selector는 6가지의 상태에 대해서 동작하도록 되어있습니다.
@color/transparent은 ColorDrawable 타입이고,
@drawable/list_selector_background_transition은 TransitionDrawable로 되어있고,
@drawable/list_selector_background_disabled과 @drawable/list_selector_background_focus은 NinePatchDrawable 타입으로 되어있습니다.
자신만의 selector를 만들 경우, 위의 xml의 구조를 따라 만들면, 쉽게 만들 수가 있습니다.
반응형
'안드로이드' 카테고리의 다른 글
[안드로이드] 여러개의 Launcher를 설치했을 때, Default Launcher 해제하기 (0) | 2011.09.06 |
---|---|
[안드로이드] SMS 발신자 변경 (SMS 와 PDU format) (0) | 2011.09.06 |
[안드로이드] Dialog의 화면 외부가 어두어지는(검은색 반투명) 동작 없애기 (0) | 2011.09.05 |
[안드로이드] 전화번호 포맷에 맞게 변환하기 (0) | 2011.09.02 |
[안드로이드] /dev 디렉토리 권한 설정 (0) | 2011.09.01 |
[안드로이드] StateListDrawable에서 Drawable 가져오기 (0) | 2011.08.31 |
[안드로이드] 메모리 누수 OutOfMemoryError 관련 링크들 (0) | 2011.08.31 |
(Mango64 & Android) Wireless Tools 포함 빌드 방법 (0) | 2011.08.25 |
(Mango64 & Android) Wireless Tools 활용법(iwconfig,iwlist) (0) | 2011.08.24 |
[안드로이드] adb로 sqlite3 사용하기 (0) | 2011.08.17 |