带有ActionbarSherlock的导航抽屉突出显示所选项目

时间:2014-01-29 06:10:20

标签: android view actionbarsherlock navigation-drawer

您好我正在使用导航抽屉,如下所示..我使用它与ABS

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="1dp"
        android:background="#ffffff"
        />
</android.support.v4.widget.DrawerLayout>

但问题是当我点击列表项时我不会突出显示,只要抽屉被打开就选择该项目..我需要在抽屉打开时突出显示所选项目,直到点击下一个项目列表。就像谷歌播放一样

1 个答案:

答案 0 :(得分:0)

你回答的是:

Android ListView selected item stay highlighted

但是,例如,请在main.java中尝试:

listView.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) {
        view.setBackgroundColor(A COLOR FOR EXAMPLE);
    }
}