Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Drawer ListView selection problems on android 2.3

I try to customize navigation drawer menu for old-good android 2.3
For this I use official SampleNavigationDrawer by developer.android.com
and this tutorial for implements ActionBarCompat.

In android.support.v4.widget.DrawerLayout use next ListView:

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:drawSelectorOnTop="false"
    android:fadingEdge="none"
    android:focusable="false"
    android:saveEnabled="true" />

with drawer_list_item.xml:

<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/bg_selector"
    android:drawableLeft="@drawable/selector"
    android:drawablePadding="16dp"
    android:gravity="center_vertical"
    android:minHeight="48dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textColor="@drawable/text_color_selector" />

bg_selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@color/yellow" />
    <item android:state_pressed="true" android:drawable="@color/red" />
    <item android:state_checked="true" android:drawable="@color/lemon" />
    <item android:state_activated="true" android:drawable="@color/orange" />
    <item android:state_selected="true" android:drawable="@color/green_pastel" />
    <item android:state_active="true" android:drawable="@color/gold" />
    <item android:state_accelerated="true" android:drawable="@color/blue" />
    <item android:state_enabled="true" android:drawable="@color/pink_dark" />
    <item android:drawable="@color/black" />
</selector>

selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/action_search" />
    <item android:state_activated="true" android:drawable="@drawable/ic_launcher" />
    <item android:drawable="@drawable/ic_drawer" />
</selector>

text_color_selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:state_pressed="true" android:color="@color/blue" />
    <item android:state_activated="true" android:color="@color/green_pastel_dark" />
    <item android:color="@color/white" />
</selector>

Problem :

For API14+ it looks awesome but on android 2.3.6 selector isn't shown. (see this screenshots)

P.S. state_activated parameter was not introduced until API level 11

like image 827
aniki.kvn Avatar asked Nov 12 '22 20:11

aniki.kvn


1 Answers

Try using ActionBar Sherlock instead. Here are some good tutorials for it: http://www.androidbegin.com/tutorial/implementing-actionbarsherlock-side-menu-navigation-with-fragment-tabs-tutorial/

http://techbandhu.wordpress.com/2013/05/25/navigation-drawer-android/

like image 132
SleepNot Avatar answered Nov 15 '22 12:11

SleepNot