Android 全屏片段不显示导航和状态栏后面的元素

问题描述

我正在开发一款 Android 游戏。它由一个主要活动和几个片段组成,通过它们的导航是通过导航组件处理的。我有一个小问题让我发疯。主要活动正确设置为全屏,状态栏和按钮栏正确隐藏,我选择的背景图像完全全屏显示。相反,说到片段,它们的元素似乎隐藏在状态栏下方,或者布局的大小不符合屏幕的实际大小。如果我在布局的最底部放置一个按钮,如您在此 screenshot 中看到的那样,屏幕上实际发生的情况是 this(请注意,该按钮被准确切割到按钮栏的位置) .我使用android studio提供的全屏片段作为模型,这些是其中使用的标志。

 int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

我也尝试在片段的根布局中添加 android:fitsSystemWindows="true",但没有奏效。

编辑
问题是由非全屏的 FragmentContainerView 以某种方式引起的。我尝试将背景设置为它而不是其父级,并且图像已被剪切:screenshot

主要活动布局是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/colourful_sound_waves_pattern_phone_wallpaper__1_"
    android:theme="@style/ThemeOverlay.LOCAL.FullscreenContainer"
    tools:context=".FullscreenActivity"
    android:id="@+id/frame_layout">
    <FrameLayout
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:fitsSystemWindows="true">
        <androidx.fragment.app.FragmentContainerView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            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:navGraph="@navigation/nav_graph" />

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="@style/Widget.Theme.LOCAL.ButtonBar.Fullscreen"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="bottom|center_horizontal"
            android:orientation="horizontal"
            tools:ignore="UselessParent">
        </LinearLayout>
    </FrameLayout>
</FrameLayout>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)