我有一个自定义的导航抽屉,里面有几个TextViews
。这是布局:
<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">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/White"
android:layout_gravity="start">
<TextView
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:textStyle="bold|italic"
android:gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="First Item" />
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="@color/gplus_color_1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:text="Second Item"
android:gravity="center_vertical"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:id="@+id/second" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
问题是,如果我不为
TextView
分配任何onClick()
,那么触摸会反映在后台的ListView
上。比如说,对于第二个TextView
,我分配了一个onClick监听器,但对于第一个TextView
,我没有这样做。当我触摸第一个TextView
时,抽屉背后的列表项会被选中,但对于第二个则不会。我如何在打开抽屉时保持导航抽屉项的焦点?