Android BottomSheet: 隐藏在工具栏下方

Android BottomSheet: Is hiding under the toolbar

我尝试使用支持库 23.2.0 中的新底部 sheet 将底部 sheet 扩展到全屏,如 design guidelines[=14= 中所建议的那样]

效果很好,但底部 sheet 在我的 ActionBar 和我的选项卡下

如何让底部 sheet 越过工具栏?我的菜单结构如下:

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

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

默认情况下 CoordinatorLayout,与任何 FrameLayout 一样,将在 API 21 及更高版本的设备上以较高的高度优先于较低的高度布局元素。

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

请注意,模态底部的高度 sheet 是 @dimen/design_bottom_sheet_modal_elevation == 16dp

如果上述答案没有帮助,请尝试设置为您的 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"/>
</android.support.design.widget.CoordinatorLayout>


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