Android 如何在工具栏中禁用抽屉切换

Android 如何在工具栏中禁用抽屉切换,android,android-toolbar,navigation-drawer,actionbardrawertoggle,Android,Android Toolbar,Navigation Drawer,Actionbardrawertoggle,在主要活动中,我得到了一个回收器视图和一个工具栏,以及一个导航抽屉。在加载回收器时,我将其和工具栏变暗,并阻止在刷卡时打开导航抽屉。但是,我无法在工具栏中禁用抽屉切换,但我希望它显示出来。我尝试了这两种选择,但都不起作用: mDrawerLayout.setDrawerListener(null); mLeftDrawerToggle.setToolbarNavigationClickListener(null); 我怎样才能做到这一点?这是我的主要布局: <android.suppo

在主要活动中,我得到了一个回收器视图和一个工具栏,以及一个导航抽屉。在加载回收器时,我将其和工具栏变暗,并阻止在刷卡时打开导航抽屉。但是,我无法在工具栏中禁用抽屉切换,但我希望它显示出来。我尝试了这两种选择,但都不起作用:

mDrawerLayout.setDrawerListener(null);

mLeftDrawerToggle.setToolbarNavigationClickListener(null);
我怎样才能做到这一点?这是我的主要布局:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- Toolbar -->
        <include android:id="@+id/appbar"
            layout="@layout/toolbar"> </include>

    </FrameLayout>

    <FrameLayout
        android:id="@+id/main_frame_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ProductsUI">

        <!-- Recycler Grid -->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/grid_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none"
            android:clipToPadding="false"
            android:paddingTop="?attr/actionBarSize"/>

        <!-- Fondo para oscurecer la pantalla -->
        <ImageView
            android:id="@+id/darken_screen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/black"
            android:visibility="gone"
            android:alpha="0.6"/>

        <!-- LoaderView -->
        <com.greenfrvr.rubberloader.RubberLoaderView
            android:id="@+id/rubber_loader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="gone"
            app:loaderExtraColor="@color/colorAccent"
            app:loaderPrimeColor="@color/colorAccent"
            app:loaderSize="medium"
            />

        <!-- Texto de error -->
        <TextView
            android:id="@+id/error_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="gone"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/error_message"
            android:textSize="20sp"
            android:textColor="@color/colorText" />

        <TextView
            android:id="@+id/nodata_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/action_bar_height"
            android:layout_gravity="center_horizontal"
            android:visibility="gone"
            android:paddingTop="@dimen/action_bar_height"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/nodata_message"
            android:textSize="20sp"
            android:textColor="@color/colorText" />

    </FrameLayout>

    <include layout="@layout/left_navigation_drawer"/>

</android.support.v4.widget.DrawerLayout>
    protected void onPreExecute()
    {
        _loading(true);
    }

    protected void onPostExecute( Void unused )
    {
        if ( error != null )
        {
               _error(true);

         } else {

               try {

                     ...

                     _loading(false);

                     ...

         }
      } // onPostExecute

     private void _loading( boolean loading )
     {
            if ( ! loading )
            {
                mRubberLoader.setVisibility(View.GONE);
                mDarkenScreenView.setVisibility(View.GONE);

                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

            } else {
                mRubberLoader.setVisibility(View.VISIBLE);
                mRubberLoader.startLoading();
                mDarkenScreenView.setVisibility(View.VISIBLE);

                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                mDrawerLayout.setDrawerListener(null); // NOT WORKING
                mLeftDrawerToggle.setToolbarNavigationClickListener(null); // NOT WORKING
            }
        }

提前感谢。

使用
mLeftDrawerToggle.setDrawerIndicatorEnabled(false)@MikeM。该方法隐藏了切换,我希望它被显示和禁用。这就是你应该在问题中包含的细节。这取决于你的活动和切换设置,你可以做什么。我不知道你所说的切换设置是什么意思,告诉我你需要什么,我会提供它。顺便说一下,我编辑了这个问题。