如何禁用或启用layout.xml中默认添加的programmaticaly layout_behavior

时间:2015-09-12 11:18:01

标签: android xml android-fragments android-support-design

我在我的项目中使用了android支持设计库。这是我的layout.xml,包含DrawerLayout,CoordinatorLayout,AppBarLayout,ToolBar和NavigationView。实际上,我的Activity包含一个NavigationDrawer,而FrameLayout @ + id / container是FragmentManager添加/替换Fragment的地方。我的问题是我有一个Fragment需要app:layout_behavior作为此容器FrameLayout的属性,另一个片段不需要它。我需要在第一个片段是容器的内容时​​启用此行为,并在另一个片段的情况下禁用它。我怎么能这样做?

我的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>

0 个答案:

没有答案