2010-08-17 4 views
11

사용자가 ListView 항목 (android : state_pressed = "true")을 누르면 노란색 음영이 깜박이거나 누르고있을 수 있습니다.목록 항목을 누르기위한 기본 drawable은 무엇입니까

어떤 드로어 블입니까? 내 ListView 항목 색을 원하기 때문에 직접 셀렉터를 만들었지 만 눌린 색은 잃어 버립니다.

# ffff0000을 참조하는 버튼을 스키닝하는 Android 관련 문서가 있지만 여기에는 빨간색이 표시됩니다.

누구인지 알고 어떻게 참조 할 수 있습니까?

답변

36

기본 시스템 리소스는 <android-sdk>/platforms/android-<version>/data/res입니다. 특히리스트 선택기 drawable/list_selector_background.xml에 정의되어

<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> 

프레스, list_selector_background_transition에 도시 된 당김이와 단색 그러나 두 -9- 패치 화상, 황색 및 백색 아니다 그것들 사이의 애니메이션 된 전환.

<transition xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@android:drawable/list_selector_background_pressed" /> 
    <item android:drawable="@android:drawable/list_selector_background_longpress" /> 
</transition> 
+2

간단히 : @android : drawable/list_selector_background_transition을 참조하려고합니다. – Jonas

+0

직접 셀렉터를 만들면 왜 @android : drawable/list_selector_background_transition을 참조 할 수 없습니까? – Andrew

+0

나는 그것을 또한 알아 차렸다. 요컨대, 나는 왜 그런지 모른다. 그러나 프로젝트에서 list_selector_background_transition의 사본을 직접 만들 수 있습니다.그런 다음 참조 할 수 있습니다. – Jonas

1

색상은 #AARRGGBB로 정의됩니다. 여기서 AA는 알파 (투명도) 값, RR은 적색, GG는 녹색 양, BB는 파란색 양입니다. 따라서 # ffff0000은 모두 단색이며 모두 빨간색입니다. 주황색을 원하면 녹색을 추가하고 싶습니다 (예 : # ffffA500). Google에서 RGB 색상 값을 사용하여 RGB 페이지의 색상을 볼 수 있습니다.

+1

네, 이걸 가지고 있습니다. 나는 안드로이드 기본값을 궁금해했다. 그러나 귀하의 회신에 감사드립니다 – Andrew

2

Android OS 기본 제공 선택기에 대해 이야기하고 있습니다.

이처럼 그릴 수-폴더에 XML 파일로 자신의 하이라이트를 확인하십시오

<?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" android:color="#YOURCOLOR" /> 
    <item android:color="#FE896F" /> 
</selector> 

그런 다음 거기 XML 파일에서 당신은 당신의 ListView있다.

android:textColor="@drawable/highlight" //For text to appear like YOURCOLOR 
//or if you wish the background 
android:background="@drawable/highlight" //For the background to appear like YOURCOLOR 

나는 이것이 이것이 효과가 있는지 알려주고 싶습니다.

+1

귀하의 회신에 감사드립니다. 나는 이미 이와 같은 선택기 파일을 만들었습니다. 나는 배경 색상을 설정 한 목록 항목에 스크롤 패드 선택기를 유지하기 위해 Romain Guy의 트릭을 사용했습니다. 내가 찾고있는 것은 Android의 기본 state_pressed 색상입니다. – Andrew

+0

누르는 항목을 인쇄하는 것과 같이 못생긴 해킹을 한 다음 RGB 색상을 찾아 볼 수 있지만 물론 기본 색상이 어딘가에 선언되어 있습니다. 문제는 그것을 찾는 방법입니다 – Curtain

+0

실제로 어떤 가치의 그라디언트처럼 보입니다 – Andrew

0

저는 사진 편집 응용 프로그램에서 색상 피커 도구를 사용하여 그라디언트의 외부 및 내부 색을 찾고 나만의 색을 만들었습니다.

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="#ffb300" 
     android:centerColor="#ffc800" 
     android:endColor="#ffb300" 
     android:angle="270"/> 
</shape> 
관련 문제