You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

三星M51设备Android Splash Activity无法设置为全屏问题求助

问题根因

  • 布局根节点配置了android:fitsSystemWindows="true",该属性会强制布局内容避开系统状态栏、导航栏区域,无法铺满全屏
  • 自定义主题同时配置了android:windowFullscreen="true"和android:windowTranslucentStatus/android:windowTranslucentNavigation,两类属性在高版本Android存在冲突,会引发黑边问题
  • 三星M51是挖孔屏设备,未适配显示切口区域,内容无法延伸到状态栏/挖孔位置,导致出现黑边
  • 旧版全屏FLAGWindowManager.LayoutParams.FLAG_FULLSCREEN在Android 11及以上版本已被废弃,三星OneUI对该废弃属性的兼容性较差

解决方案

1. 修改布局配置

删除根布局的android:fitsSystemWindows="true"属性,修改后如下:

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_layout_screen">

2. 修正自定义主题

移除冲突的半透明属性,新增挖孔屏适配配置:

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <!-- 适配挖孔屏,内容延伸到切口区域 -->
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    <!-- 隐藏导航栏可选配置,按需添加 -->
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>

3. 新增高版本Android全屏兼容代码

在SplashActivity的onCreate方法setContentView之前添加如下兼容代码:

// Kotlin代码示例,Java可对应转换
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.apply {
        hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
        systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    }
    // 适配挖孔区域
    window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
} else {
    window.setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
    )
}
requestWindowFeature(Window.FEATURE_NO_TITLE)

内容的提问来源于stack exchange,提问作者Jaimin Modi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 07:42:03