如何在底部应用栏前设置FAB?
How to set FAB in front of bottom app bar?
如何将浮动操作按钮置于底部应用栏的前面?
换句话说,如何设置底部的应用栏来填满fab后面的整行?
来自:
为此:
图片来自 medium.com
根据 this tutorial 应该有一个名为 fabCradleDiameter
的属性,但实际上这个组件没有这样的属性。
是的,没有名为 fabCradleDiameter
的属性,它的 fabCradleMargin
并确保版本在:
之后
com.google.android.material:material:1.0.0-alpha3
试试这个对我有用..可能对你也有用。
<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" />
关键是使用新的 material 主题。您的容器布局也应该是协调器布局。使用以下代码更改您的布局。
<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>
就用官方的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"
.../>
如何将浮动操作按钮置于底部应用栏的前面? 换句话说,如何设置底部的应用栏来填满fab后面的整行?
来自:
为此:
图片来自 medium.com
根据 this tutorial 应该有一个名为 fabCradleDiameter
的属性,但实际上这个组件没有这样的属性。
是的,没有名为 fabCradleDiameter
的属性,它的 fabCradleMargin
并确保版本在:
之后com.google.android.material:material:1.0.0-alpha3
试试这个对我有用..可能对你也有用。
<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" />
关键是使用新的 material 主题。您的容器布局也应该是协调器布局。使用以下代码更改您的布局。
<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>
就用官方的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"
.../>