1

如何将浮动操作按钮放在底部应用栏的前面?换句话说,如何将底部应用栏设置为填充 fab 后面的整行?

由此: 在此处输入图像描述

对此: 在此处输入图像描述

图片来自 medium.com

根据本教程应该有一个名为的属性fabCradleDiameter,但实际上这个组件没有这样的属性。

4

4 回答 4

2

是的,没有一个名为 的属性fabCradleDiameter,它的fabCradleMargin

并确保版本在:

com.google.android.material:material:1.0.0-alpha3
于 2018-11-21T21:51:23.847 回答
2

试试这个它对我有用..也可能对你有用。

<android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center"
        app:fabCradleMargin="0dp"
        app:fabCradleRoundedCornerRadius="0dp"
        app:hideOnScroll="true"
        app:navigationIcon="@drawable/ic_menu_black_24dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_favorite_red_24dp"
        app:borderWidth="0dp"
        app:fabSize="normal"
        app:layout_anchor="@id/bottomAppBar" />
于 2018-11-23T05:49:45.967 回答
1

只需使用官方BottomAppBar并使用:

  • fabCradleMargin属性。它增加或减少之间的FloatingActionButton距离BottomAppBar
  • fabCradleRoundedCornerRadius属性。它指定切口周围角的圆度

利用:

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bar"
    android:layout_gravity="bottom"
    app:fabCradleMargin="0dp"
    app:fabCradleRoundedCornerRadius="0dp"
    ... />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    app:layout_anchor="@id/bar"
    .../>

在此处输入图像描述

于 2019-08-26T19:50:56.433 回答
0

关键是使用新的材质主题。此外,您的容器布局应该是协调器布局。使用下面的代码来改变你的布局。

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

  <!-- Other components and views -->

  <com.google.android.material.bottomappbar.BottomAppBar
      android:id="@+id/bar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      style="@style/Widget.MaterialComponents.BottomAppBar"      //Material style. 
      app:navigationIcon="@drawable/ic_menu_24"/>

  <com.google.android.material.floatingactionbutton.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:layout_anchor="@id/bar"/>

</android.support.design.widget.CoordinatorLayout>
于 2018-11-23T06:14:28.093 回答