android - ActionBar 下方的持久性 BottomSheet

标签 android android-layout android-actionbar bottom-sheet

我有一个带有自定义 toolbar 的应用程序布局和一个持久的BottomSheet - 都在 CoordinatorLayout 内.

单击按钮我想显示 BottomSheet .现在工作表全屏显示并覆盖 toolbar .通过将应用程序主题设置为 Theme.AppCompat.Light.DarkActionBar BottomSheet保持在 ActionBar 以下, 但无法自定义栏。

有没有办法限制persitent的高度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>

Screenshot 左侧的图像显示 BottomSheetToolbar 下方停止- 这不适用于我当前的代码。目前它看起来像右边的图片。

最佳答案

我遇到了同样的问题...我不知道这是否是最好的解决方案,但就目前而言,它对我有用。

尝试将您的 include 放入 activity_main.xml 的另一个 CoordinatorLayout 中,像这样使用 marginTop:

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

    <android.support.design.widget.CoordinatorLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="56dp">
      
      <include layout="@layout/bottom_sheet_additem"/>

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

</CoordinatorLayout>

希望对你有帮助。

关于android - ActionBar 下方的持久性 BottomSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42491378/

相关文章:

java - android opengl es 1.1 - 某些设备上的绘图故障 - 内部屏幕截图

android - 从命令行运行 adb 会使设备离线

android - 使屏幕底部出现在键盘上方

android - 如何禁用选项卡 Selected 上 FragmentPagerAdapter 中第一个 fragment 的重新创建?

屏幕中间的android导航选项卡

android - ActionBarSherlock - 使用自定义 View 显示在操作栏上方的选项卡

java - 支持MapFragment和NullPointerException

android - 发送外发短信时如何知道SIM卡或手机号码?

java - 针对具有多种布局的 Android 优化代码

Android 小部件位图大小