[英]How to make cradled FAB in Jetpack Compose Material 3?
我正在尝试使用 Jetpack Compose Material 3 制作 Cradled FAB。基于本网站文档中的图像:https://m3.material.io/components/bottom-app-bar/implementation
但是在代码中我找不到任何关于在哪里指定锚点 position 或将晶圆厂设置为停靠的信息。 示例代码是 XML,我正在使用 Compose。 这是怎么做到的? 我现在正在使用 Scafold 和 BottomAppBar,但它们似乎没有任何选项来停靠或固定浮动操作按钮。
我没有使用 Material Compose 库,但最近我在从 Material 2 迁移到 Material 3 时遇到了同样的问题。
https://pasteboard.co/LWzXHPOg3waX.jpg
在我的 BottomAppBar 组件上添加app:fabAnchorMode="cradle"属性为我解决了这个问题。
https://pasteboard.co/qmZE2NQovGFq.png
这是一个代码示例
<androidx.coordinatorlayout.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=".MyActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/my_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/my_fab_description"
android:src="?attr/myFabIcon"
app:layout_anchor="@+id/my_bottom_app_bar" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/my_bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/global_action_bar_height"
android:layout_gravity="bottom"
app:backgroundTint="?attr/myBottomAppBarColor"
app:fabAlignmentMode="end"
app:fabAnchorMode="cradle"
app:fabCradleMargin="@dimen/bottom_action_bar_fab_cradle_margin"
app:hideOnScroll="true"
app:menu="@menu/my_bottom_app_bar_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
其中一种选择是使用脚手架,您可以设置“floatingActionButtonPosition”
Scaffold(
bottomBar = { //bottomBar sample },
floatingActionButton = {
//Button
},
floatingActionButtonPosition = FabPosition.Center,
content = {//your content
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.