状态栏与应用程序的工具栏重叠,并且工具栏在 Android API 30+ 上消失了

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

我在 Android API 30+ 上遇到应用程序工具栏问题。设备的状态栏与我的应用程序的工具栏重叠,并且工具栏消失了。 API 低于 30(29、28、27、...)的设备上不会出现此问题。我搜索了Stackoverflow,但没有找到适合我的案例的任何可行解决方案。

我尝试过

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
它会带回工具栏并以全屏模式显示应用程序,但设备的状态栏和底部导航栏与应用程序的内容重叠(半透明)。

我想要的是设备的状态栏和底部导航栏不与应用程序的内容重叠。它们可以出现或消失。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Main content -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- Toolbar -->
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar_main"/>

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar" />

        <!-- Loading box -->
        <RelativeLayout
            android:id="@+id/boxProgress"
            android:layout_width="@dimen/loading_box_size"
            android:layout_height="@dimen/loading_box_size"
            android:layout_centerInParent="true"
            android:layout_gravity="center"
            android:visibility="gone">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:alpha="0.8"
                android:background="@drawable/background_round_corner" />

            <ProgressBar
                android:id="@+id/progressBar"
                style="?android:attr/progressBarStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="@dimen/box_margin_medium"
                android:indeterminate="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/progressBar"
                android:layout_centerHorizontal="true"
                android:text="@string/label_status_loading"
                android:textSize="@dimen/text_size_medium" />

        </RelativeLayout>
    </RelativeLayout>

    <!-- Order drawer (slide from right) -->
    <FrameLayout
        android:id="@+id/drawer"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="end" />

</androidx.drawerlayout.widget.DrawerLayout>

toolbar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="36dp"
    android:contentInsetEnd="0dp"
    android:contentInsetLeft="0dp"
    android:contentInsetRight="0dp"
    android:contentInsetStart="0dp"
    android:contentInsetStartWithNavigation="0dp"
    android:fitsSystemWindows="true"
    android:minHeight="36dp"
    android:theme="@style/ToolbarStyle"
    android:layout_marginBottom="@dimen/box_margin_bottom_small"
    app:contentInsetEnd="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <ImageView
        android:id="@+id/toolbarIndicator"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:scaleType="centerInside"
        android:padding="@dimen/box_padding_small"/>

    <FrameLayout
        android:id="@+id/toolbarContainer"
        android:layout_width="match_parent"
        android:layout_height="36dp" />

</androidx.appcompat.widget.Toolbar>

应用主题

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">...</style>
android android-layout android-actionbar android-statusbar android-fullscreen
1个回答
0
投票

我终于成功了!!过去我曾经将以下代码添加到

MainActivity.kt
中的onCreate()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
   this.window.setDecorFitsSystemWindows(false)
}

删除后,一切都恢复原状。谢谢 C.F.G 让我了解

fitSystemWindows
房产。

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