2016-01-05 35 views
2

因此,基本上我們昨天實施了一個導航抽屜到我們的項目中,因爲我們無法再點擊頁面上的項目,就好像抽屜仍然覆蓋頁面,即使關閉啓用我們點擊頁面上的任何內容。有沒有辦法啓用點擊這個「關閉」導航抽屜下面的元素?導航抽屜無法點擊頁面(Android Studio)

這是我們使用導航抽屜的頁面的一個小竅門,即使抽屜關閉,我們也無法點擊單個開關按鈕。

<?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> 

回答

1

當您想要使用導航抽屜時,佈局中的第一個元素應始終爲drawerlayout。從官方Android開發者網站摘自:

要與 DrawerLayout對象作爲佈局的根視圖中添加抽屜式導航,宣佈你的用戶界面。

我強烈建議您從官方的android網站上讀取this,然後重做您的代碼。

+0

非常感謝,堅持了兩天,其他人做了這部分代碼,所以我根本不知道如何正確使用它,抱歉做出這樣的虛假錯誤 – Akorna

+0

@Akorna不用擔心,只是一個如果您將來要開發android應用程序,請提示 - 總是首先查看官方的android文檔,但您找不到比這更好的文檔。 –

0

不要在DrawerLayout中添加新的視圖,它可以攔截觸摸事件。