1

如何以这种样式设置工具栏的样式,如底部应用栏的材料指南中所示?

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

截屏: 材料设计指南

4

1 回答 1

0

所以,你正试图一起实现那个Toolbar白色BottomAppBar。它是如此容易。

为此,添加AppBarLayoutwith Toolbarin CoordinatorLayout,将BottomAppBarandFloatingActionButton放入 parentCoordinatorLayout并将app:layout_anchor属性设置FloatingActionButton为引用 id ,BottomAppBar如下所示:

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

于 2018-09-06T16:58:56.333 回答