2015-02-04 4 views
0

선택하면 서랍 목록을 강조 표시하려고합니다.탐색 창에서 ListItem을 강조 표시로 표시하는 방법

내 탐색 창 목록보기는 다음과 같습니다

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 
     . 
     . 
     . 
     <LinearLayout 
      android:id="@+id/drawer_view" 
      android:layout_width="304dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="left|start" 
      android:fitsSystemWindows="true"> 

      <!-- Your drawer content --> 

      <ListView 
       android:id="@+id/left_drawer" 
       style="@style/NavDrawer" 
       android:layout_width="320dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="start" 
       android:listSelector="@drawable/drawer_listview_background_selector" 
       android:background="@color/icons" 
       android:choiceMode="singleChoice" 
       android:divider="@color/divider" 
       android:dividerHeight="0dp" /> 
     </LinearLayout> 

    </android.support.v4.widget.DrawerLayout> 

서랍 목록 항목은 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/drawer_listview_background_selector" 
    android:gravity="center_vertical" 
    android:minHeight="48dp" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:textSize="14sp" 
    android:textColor="@color/primary_text" /> 

선택기은 다음과 같습니다 onItemSelected 방법에

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="true" android:state_pressed="true" android:drawable="@color/primary" /> 
    <item android:state_enabled="true" android:state_focused="true" android:drawable="@color/primary" /> 
    <item android:state_enabled="true" android:state_selected="true" android:drawable="@color/primary" /> 
    <item android:drawable="@drawable/normal" /> 
</selector> 

내가 뭐하는 거지 :

참고로 73,210

것은 내가하여 ListItem 레이아웃

android:background="?android:attr/activatedBackgroundIndicator" 

를 사용하는 경우가 매우 잘 작동하는지,하지만 내 안드로이드 4.4.4에 홀로 색상을 적용합니다.

자주 묻는 질문의 대부분을 읽고 테스트했지만 실패했습니다.

답변

1

활성화 된 상태에 사용할 색이나 드로어를 선택하여 <selector>android:state_activated<item>을 추가하십시오.

+0

예, 누락되었습니다. 선택한 항목의 텍스트 색상을 변경하기 위해 별도의 ''을 사용할 수 있습니까? 아니면 더 좋은 방법이 있습니까? –

+0

@ShajeelAfzal :'TextView'는 [ColorStateList'] (http://developer.android.com/reference/android/content/res/ColorStateList.html)를 사용할 수 있습니다. 또한 ''구문을 사용합니다. – CommonsWare

관련 문제