【发布时间】:2017-07-18 09:33:56
【问题描述】:
我有一个带有自定义 toolbar 和持久 BottomSheet 的应用布局 - 两者都在 CoordinatorLayout 内。
单击按钮时,我想显示BottomSheet。现在工作表全屏显示并覆盖toolbar。通过将应用主题设置为Theme.AppCompat.Light.DarkActionBar,BottomSheet 保持在ActionBar 下方,但无法自定义栏。
有没有办法将持久性BottomSheet 的高度限制为全屏 - ActionBar 高度?
这是我在activity_main.xml中的代码
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:attrs="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:elevation="20dp"
android:elevation="20dp"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:elevation="20dp"
android:elevation="20dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
<include layout="@layout/bottom_sheet_additem"/>
</CoordinatorLayout>
这里是sheet_bottom.xml的代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
android:fitsSystemWindows="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:id="@+id/bottomsheet_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Lorem Ipsum Dolor..."
android:textColor="#FFFFFF" />
</RelativeLayout>
左侧的图像显示了BottomSheet,它在Toolbar 下方停止 - 这不适用于我当前的代码。目前看起来如右图所示。
【问题讨论】:
-
可以上传截图吗?
-
屏幕截图添加到问题 - 编辑
-
您尝试将布局设置为从底部到工具栏的高度,并将底部表设为子级,然后将其设置为与父级高度匹配(新布局)
-
谢谢!伟大而简单的想法。让它工作的另一件事 BottomSheet 必须是 CoordinatorLayout 的孩子!
-
就像将 coordinatorLayout 设置为新的父高度一样简单,所以它就像:Layout -> coordinator -> bottomsheet
标签: android android-layout android-actionbar bottom-sheet