我正在尝试自定义底部栏和浮动按钮位置,但我被卡住了,无法找到一种方法来做到这一点。
现在,底部的 bar 和 fab 看起来像这样:
晶圆厂的中心与底部条的顶部对齐,但我希望它位于底部条的中心,而不是与顶部对齐。
下面是代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.HomeActivity">
<fragment
android:id="@+id/nav_host_fragment_home"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_home_graph" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="20dp"
app:fabCradleVerticalOffset="0dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="@android:color/transparent"
app:menu="@menu/nav_bottom_bar" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="add"
app:fabSize="mini"
app:srcCompat="@drawable/ic_nav_upload"
app:layout_anchor="@id/floating_action_video"
app:layout_anchorGravity="center"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="add"
app:fabSize="mini"
app:srcCompat="@drawable/ic_nav_video"
app:layout_anchor="@id/floating_action_button"
app:layout_anchorGravity="center"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="add"
app:srcCompat="@drawable/ic_nav_add"
app:layout_anchor="@id/bottomAppBar"
app:layout_anchorGravity="center"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
另外,当点击它时,我会打开一个如下所示的菜单:
我想设置一个背景,让相机图标和 lib 图标看起来像连接到“+”按钮。所以 3 按钮共享相同的背景。一种包含所有内容的布局
任何想法 ?