我尝试为老式的 android 2.3 自定义导航抽屉菜单
为此,我使用developer.android.com 的官方SampleNavigationDrawer
和本教程实现ActionBarCompat。
在android.support.v4.widget.DrawerLayout中使用下一个 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" />
与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>
选择器.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>
问题 :
对于 API14+,它看起来很棒,但在 android 2.3.6 上没有显示选择器。(见此截图)
PS state_activated 参数直到 API 级别 11 才引入