Android -Settings for navigation boxes scroll list / focused

I have a custom navigation box with a couple TextViews

. Here's 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 that if I don't assign <<22> to TextView

then the touch is reflected to ListView

which is in the background. Let's say for the second one TextView

I assigned an onClick listener, but for the first one TextView

I didn't, when I touch the first TextView

, the list item behind the drawer is selected, but not for the second. How to keep focus on navigation drawer items when opening drawer?

+3


source to share


1 answer


add android: clickable = "true" to ur LinearLayout. It stops focusing on 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">

      

+5


source







All Articles