【问题标题】:style Toolbar for using with bottom app bar用于底部应用栏的样式工具栏
【发布时间】:2019-02-11 03:00:37
【问题描述】:

如何在 this style 中设置 Toolbar 的样式,如底部应用栏的 Material Guidelines 中所示?

它是白色的,没有高度,比平时有更多的标题顶部填充等。我在 Material Guidelines 中找不到任何规格或在 material-components-android 中找到任何主题参考。

截图:

【问题讨论】:

  • 这只是一个设计,你可以按照你认为合适的方式实现它。
  • @KeivanEsbati 我知道这只是一个设计。我想知道是否有可用的指南。

标签: android android-toolbar material-components android-bottomappbar


【解决方案1】:

所以,您正在尝试实现白色 Toolbar 和 BottomAppBar 一起。就是这么简单。

为此,在CoordinatorLayout 中添加AppBarLayout 和Toolbar,将BottomAppBar 和FloatingActionButton 放入父CoordinatorLayout 并将FloatingActionButton 的app:layout_anchor 属性设置为@ 的引用ID 987654333@如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/yourwhitebackground"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/yourwhitebackground"
        app:layout_collapseMode="pin"
        app:layout_scrollFlags="scroll|enterAlways"
        />
</android.support.design.widget.AppBarLayout>

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/bottom_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:fabAttached="true"
        app:backgroundTint="@color/colorPrimary"
        app:fabCradleVerticalOffset="12dp">

    </android.support.design.bottomappbar.BottomAppBar>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:src="@drawable/ic_add_white_24dp"
        app:layout_anchor="@+id/bottom_appbar"/>


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

阅读:https://medium.com/@lupajz/the-place-for-bottomappbar-31e0db8f70b1了解更多详情。

另外,app:elevation 可能不起作用,试试这个:https://stackoverflow.com/a/45703684/4409113

【讨论】:

  • 我的问题是关于工具栏样式,而不是 FAB。很抱歉造成混乱。
  • 我已经更新了答案。一开始很混乱,但现在一切都清楚了。
  • 我正在寻找它的规格,而不是如何实际添加一个白色背景且没有高度的工具栏。
  • 糟糕,我以为您正在寻找按钮栏实现。这只是一个设计,只需移除立面并使其变为白色。在材料指南中找不到任何规格,因此可能没有。
  • @Mohsen 底部应用栏的高度已在 1.1.0 (alpha) 版中得到修复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 2018-06-19
  • 1970-01-01
  • 1970-01-01
  • 2017-03-18
相关资源
最近更新 更多