我已尝试按照以下准则实施材料组件底部的应用栏,并重构到AndroidX +更新我的AppTheme。 Material components - bottom app bar
这是我的xml代码:
<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"
android:fitsSystemWindows="true">
<!-- Other components and views -->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottombar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:elevation="2dp"
app:fabAlignmentMode="center"
app:fabCradleVerticalOffset="10dp"
app:fabCradleMargin="10dp" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:adjustViewBounds="true"
app:layout_anchor="@id/bottombar"
app:layout_anchorGravity="top|center"
app:srcCompat="@drawable/marker" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我什至增加了fabCradleMargin
和fabCradleOffset
-否则按钮完全在底部,并且根本不应该悬浮在该半圆内...
有人对此有任何线索吗?非常感谢!
答案 0 :(得分:0)
因此,我注意到这与底部应用栏的高度有关。如果我手动将其设置为80dp
,则Fab将按预期显示。
我尝试了一些,发现此手动高度设置仅在片段中是必需的。我只将底部的应用程序条放在一个片段中以进行测试。
因此,现在我以与MainActivity
中的准则相同的方式来实现它,然后设置一个函数showFab(Boolean enable)
,然后可以根据需要在不同的片段中对其进行调用。
如果有人面对相同的问题,那么它就像一个魅力。我想这可能是因为它不应该仅在单个片段中实现。