我在我的项目中使用了 android 支持设计库。这是我的带有 DrawerLayout、CoordinatorLayout、AppBarLayout、ToolBar 和 NavigationView 的 layout.xml。其实我的Activity里面有一个NavigationDrawer,FrameLayout@+id/container就是FragmentManager添加/替换Fragment的地方。我的问题是我有一个 Fragment 需要 app:layout_behavior 作为此容器 FrameLayout 的属性,而另一个 Fragment 不需要它。我需要在第一个片段是容器的内容时启用此行为,并在另一个片段的情况下禁用它。我怎样才能做到这一点 ?
我的 activity_main.xml :
<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"
tools:context="com.hhsociete.mybootstrap.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- The ActionBar -->
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:menu="@menu/drawer_view"
app:headerLayout="@layout/nav_header"/>
</android.support.v4.widget.DrawerLayout>