我创建了一个导航抽屉,但我没有放一个列表视图,而是放置了一个带有两个listview的relativelayout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/colorPrimary"
android:fitsSystemWindows="false"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<RelativeLayout
android:layout_gravity="start"
android:background="@color/nd_background"
android:layout_width="300dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="@string/app_name"
android:textColor="@color/nd_image_text"
android:gravity="bottom"
android:textSize="15sp"
android:padding="15dp"
android:background="@drawable/navigation_drawer_image"/>
<ListView
android:id="@+id/nd_list_1"
android:layout_below="@id/image"
android:dividerHeight="2dp"
android:divider="@color/white"
android:choiceMode="singleChoice"
android:drawSelectorOnTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="@+id/divider"
android:layout_below="@id/nd_list_1"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/darker_gray"/>
<ListView
android:id="@+id/nd_list_2"
android:layout_below="@id/divider"
android:divider="@color/white"
android:choiceMode="singleChoice"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
现在我想在选择特定行时突出显示列表视图项,因此我使用listview函数 setSelection ,但所选行不会突出显示。当我只将listview放入导航抽屉时,我确实工作了,但不是这样。