Akorna
Akorna

Reputation: 217

Navigation Drawer unables clicks on page (Android Studio)

So basicly we implemented a Navigation Drawer to our project yesterday and since we can't click on items on our page anymore, as if the drawer still overlays the page even when closed enabling us to click on anything on the page. Is there a way to enable clicking on the elements below this "closed" navigation drawer?

Here's a sniplet of one of our pages using the Navigation Drawer, we're unable to click the single switchbutton even when the drawer is closed.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.cocacola.fastgids.SettingsActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:fitsSystemWindows="true" tools:openDrawer="start"
        android:elevation="4dp"
        >

        <android.support.design.widget.NavigationView android:id="@+id/nav_view"
            android:layout_width="wrap_content" android:layout_height="match_parent"
            android:layout_gravity="start" android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
    </android.support.v4.widget.DrawerLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/setting_Bootanim"
        android:id="@+id/textView2"
        android:layout_marginLeft="22dp"
        android:layout_marginStart="22dp"
        android:layout_below="@+id/my_toolbar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="28dp" />

    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/switchAnimation"
        android:checked="true"
        android:text="Disable/Enable"
        android:layout_below="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="21dp" />


</RelativeLayout>

Upvotes: 2

Views: 174

Answers (2)

Michael
Michael

Reputation: 666

don't add new View in DrawerLayout, it could intercept touch event.

Upvotes: 0

Ludwig S
Ludwig S

Reputation: 551

The first element in your layout when you want to use a navigation drawer, should always be a drawerlayout. Taken from the official Android developer site:

To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout.

I would highly suggest that you read this from the official android site, and redo your code.

Upvotes: 1

Related Questions