Reputation: 3675
I have a custom Navigation Drawer with a couple of TextViews
. Here is the layout:
<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>
The problem is, if I don't assign any onClick()
for the TextView
, then the touch is reflected on the ListView
which is in the background. Say, for the second TextView
I assigned an onClick listener but for the first TextView
I didn't, when I touch on the first TextView
the list item behind the drawer gets selected but not for the second. How do I keep the focus on the navigation drawer items when the drawer is opened?
Upvotes: 3
Views: 1355
Reputation: 3344
add android:clickable="true" to ur LinearLayout. It stop focusing to the background list.
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical"
android:background="@color/White"
android:layout_gravity="start">
Upvotes: 6