我用Material Design 3设计了我的应用程序,我用的是bottom navigation bar.

<!-- activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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=".MainActivity">

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/nav_graph"
        tools:ignore="FragmentTagUsage" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>

我加了floating action button (FAB).

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/add_a_vehicle_fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    android:contentDescription="@string/fab_content_description"
    app:srcCompat="@drawable/ic_baseline_add_24" />

然而,晶圆厂被隐藏在导航栏后面.

Bottom navigation bar with obscured FAB

我试图通过在下面的片段中添加边距来解决这个问题:How to get the ActionBar height?.

<fragment
    android:id="@+id/nav_host_fragment"
    ....
    android:layout_marginBottom="?android:attr/actionBarSize"
    ... />

然而,这个高度是从Material Design 2 bottom navigation bar开始的,我的晶圆厂被切断了,因为它没有足够的利润.

Bottom navigation bar with FAB cutoff

How do I obtain the height of the Material Design 3 bottom navigation bar so I can display my FAB correctly?

推荐答案

With Material3 the BottomNavigationView has a different minHeight.
You can apply something like:

   <fragment
        android:layout_marginBottom="@dimen/m3_bottom_nav_min_height"

enter image description here

参考:android/material/bottomnavigation/res/values/dimens.xml#L32

Android相关问答推荐

ArrayList.remove()(Kotlin中的removeAt())导致奇怪的IndexOutOfBoundsResponse异常

打开平板电脑的下载文件夹中的文件,例如使用其mimeType将Intent发送到我们的应用程序

Android:MethodHandle. invoke和MethodHandle. invokeExact仅从Android O( - min—api 26)开始支持

在以XML格式设置完整屏幕视图时可见App Compat按钮

Play Google上发布的一款应用的房间数据库迁移

Kotlin为多个控件设置一个侦听器

在 kotlin 上向适配器添加绑定视图功能

Camera2 将图像从 ImageReader 传递到 MediaRecorder

如何迭代 SqlDelight Select 结果而不将所有内容加载到内存中?

Jetpack Compose 中的用户在线指示器

在一个函数中组合相同的流 struct

如何从 firebase 实时数据库中检索最后一个值

Android 设备断开连接后发送的 BLE 蓝牙数据

Jetpack Compose 动画的行为是什么?

在 Jetpack Compose 中包装内容

有什么方法可以确定正在使用哪个 Android 手机的麦克风进行录音?

如何修复 api 调用在浏览器中工作但在 android studio 中为 403

优化 Room 数据库迁移

使 Compose LazyColumn 的最后一项填满屏幕的其余部分

未解决的参考:getIntentSender / try 在 Jetpack Compose 中获取电话号码时