Android 隐藏导航抽屉

Android 隐藏导航抽屉,android,navigation-drawer,Android,Navigation Drawer,Im我的应用程序我有一个名为main Activity的活动,它包含一个id为container的动态片段,我会根据状态进行切换。通常我的应用程序可以处于synching或Regular状态,现在我不想在其中添加NavigationDrawer,我希望它在操作栏和屏幕上可见仅当main活动未处于Synching状态时,才会显示左侧,因为如果活动Synching我不应该使用抽屉在我的应用程序中导航。 Im使用以下活动布局 <!-- A DrawerLayout is intended to

Im我的应用程序我有一个名为
main Activity
的活动,它包含一个id为
container
的动态片段,我会根据状态进行切换。通常我的应用程序可以处于
synching
Regular
状态,现在我不想在其中添加
NavigationDrawer
,我希望它在操作栏和屏幕上可见仅当
main活动
未处于
Synching
状态时,才会显示左侧,因为如果活动
Synching
我不应该使用抽屉在我的应用程序中导航。 Im使用以下活动布局

<!-- A DrawerLayout is intended to be used as the top-level content view using 
  match_parent for both width and height to consume the full space available. -->

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="pt.ecs.myenergy.MainActivity">

<!-- As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions. -->
<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     If you're not building against API 17 or higher, use
     android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
     the container. -->
<fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="---------.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

问题是要找到一个聪明/最好的方法来实现这一点。我想到了几个,但我不确定该用哪一个:

  • 为活动设置两个xml布局,一个包含抽屉,另一个不包含抽屉,并使用setContentView,这将导致xml膨胀不确定这是否是一个好的方法
  • 将合并标记与两个孩子一起使用一个抽屉布局(与容器一起),另一个仅与容器一起使用(用于同步)

  • 我建议不要做这些选择。对我来说,他们似乎都太复杂了

    您应使用以下方法锁定已关闭的抽屉:


    如果你也在使用一个
    ActionBarDrawerToggle
    你用Perfect禁用了它的指示器,我知道
    setDrawerIndicatorEnabled
    但是错过了
    setDrawerLockMode
    谢谢你会尝试它