Android BottomSheet:隐藏在工具栏

时间:2016-02-29 23:27:18

标签: android material-design android-support-library androiddesignsupport

我尝试使用支持库23.2.0中的新底页将底页扩展为全屏,如design guidelines

中所示

这非常好,但是底页在我的ActionBar 下面和我的标签下

如何让底页超出工具栏?我的菜单结构如下:

    

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|snap|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <include
        android:id="@+id/playerLayout"
        layout="@layout/player_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_peekHeight="?attr/actionBarSize"
        app:layout_behavior="@string/bottom_sheet_behavior"
        app:model="@{model}"/>

</android.support.design.widget.CoordinatorLayout>

enter image description here

2 个答案:

答案 0 :(得分:46)

AppBarLayout的默认高程为4dp(维度资源值design_appbar_elevation)。

默认情况下,CoordinatorLayout与任何FrameLayout一样,会在API 21及更高设备的较低高度之前布置具有较高海拔的元素。

尝试将android:elevation="@dimen/design_appbar_elevation"添加到您的布局中。

请注意,模态底部工作表的高程为@dimen/design_bottom_sheet_modal_elevation == 16dp

答案 1 :(得分:2)

如果以上答案没有帮助,请尝试将其设置为BottomSheet:

android:elevation="@dimen/design_appbar_elevation" android:fitsSystemWindows="true"

以这种方式创建片段:

videoFragment = VideoFragment.newInstance(); getSupportFragmentManager().beginTransaction() .replace(R.id.video_fragment, videoFragment) .commit();
不是这样的: videoFragment = (VideoFragment) getSupportFragmentManager().findFragmentById(R.id.video_fragment);

例如,我有这样的布局:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/activity_background">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

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

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:itemBackground="@color/white"
    app:menu="@menu/bottom_navigation_main"/>

<FrameLayout
    android:id="@+id/video_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="@dimen/design_appbar_elevation"
    android:fitsSystemWindows="true"
    app:behavior_hideable="true"
    app:behavior_peekHeight="0dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>


,没有指定的东西就无法工作