浮动操作按钮在真实设备中显示的位置错误

问题描述 投票:0回答:1

我根据指南创建了一个带有 BottomAppBar 和浮动操作按钮的活动。当我在 Genymotion 中运行它时,它的效果符合我的预期。

In the Genymotion

但是当我将其导出为apk文件并安装到小米设备(MIUI 13 - Android 12 SKQ)时,它并没有按照我的预期工作(向左偏离)。

In the Xiaomi Device

不知道是什么原因。

这是我的xml源代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    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:id="@+id/draw_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black">
        
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbarMain"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/red"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

        <FrameLayout
            android:id="@+id/frameMainContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <com.google.android.material.bottomappbar.BottomAppBar
                android:id="@+id/bottomAppBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="@color/red"
                app:fabCradleMargin="10dp"
                app:fabCradleRoundedCornerRadius="50dp">
                <com.google.android.material.bottomnavigation.BottomNavigationView
                    android:id="@+id/bottomNavMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:backgroundTint="@color/red"
                    android:visibility="visible"
                    app:labelVisibilityMode="labeled"
                    app:menu="@menu/bottom_navigation_menu" />
            </com.google.android.material.bottomappbar.BottomAppBar>

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/fabCenter"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/baseline_add_circle_outline_24"
                app:layout_anchor="@id/bottomAppBar"/>
        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </RelativeLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navViewDrawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/black"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:headerLayout="@layout/app_header"
        app:menu="@menu/drawer_navigation_menu"/>

</androidx.drawerlayout.widget.DrawerLayout>

我试图研究一些东西,但没有文章提到它。 我希望我能收到问题的解决方案

android
1个回答
0
投票

我已经找到答案了。 根本原因是主题设置不正确。 (虚拟机中使用夜间主题,真机中使用深色主题)

© www.soinside.com 2019 - 2024. All rights reserved.