基本上我们昨天在我们的项目中实现了一个抽屉导航,因为我们不能再点击我们页面上的项目,就好像即使在关闭时抽屉仍然覆盖页面,使我们能够点击页面上的任何内容。有没有办法允许点击这个“关闭”的抽屉导航下面的元素?
这是我们使用抽屉导航的页面之一的 fragment ,即使抽屉已关闭,我们也无法单击单个切换按钮。
<?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>
最佳答案
当你想使用抽屉导航时,布局中的第一个元素应该始终是抽屉布局。摘自官方 Android 开发者网站:
To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout.
我强烈建议您阅读 this从官方 android 网站,重做你的代码。
关于java - 抽屉导航无法点击页面(Android Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34607432/