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

Android应用无法全屏显示?模拟器与真机均存在该问题

Android应用无法全屏显示排查方案

1. 修复Manifest配置语法错误

你提供的Manifest存在语法问题:Activity配置未包裹在<activity>标签内,直接写在了<application>节点下,导致Activity级别的主题、屏幕方向配置不生效。修正后的配置如下:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MyApplication"
    android:usesCleartextTraffic="true">
    <!-- 新增activity标签包裹Activity配置 -->
    <activity
        android:name=".Activity.acilis"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.MyApplication.FullScreen"
        tools:ignore="LockedOrientationActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

2. 新增全屏专用主题样式

在你的主题样式文件中新增全屏主题,按需选择沉浸式或完全全屏配置:

<style name="Theme.MyApplication.FullScreen" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="forceDarkAllowed">false</item>
    <!-- 基础无标题栏配置 -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <!-- 完全全屏:隐藏状态栏和导航栏 -->
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <!-- 沉浸式全屏:布局延伸到系统栏下方,如需这个效果替换上面的windowFullscreen配置即可
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    -->
    <!-- 适配刘海屏、挖孔屏,允许内容延伸到切口区域 -->
    <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="p">shortEdges</item>
</style>

3. Activity代码动态适配(可选,适配高版本系统)

如果需要实现沉浸式sticky全屏(滑动边缘才会临时显示系统栏),在Activity的onCreate方法中添加如下代码:

// Kotlin 示例
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.setDecorFitsSystemWindows(false)
    window.insetsController?.apply {
        hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
        systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    }
} else {
    @Suppress("DEPRECATION")
    window.decorView.systemUiVisibility = (
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_FULLSCREEN
    )
}
// Java 示例
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    getWindow().setDecorFitsSystemWindows(false);
    WindowInsetsController controller = getWindow().getInsetsController();
    if (controller != null) {
        controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
        controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    }
} else {
    getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
    );
}

注意:不要在布局根节点添加android:fitsSystemWindows="true"属性,否则会阻止布局延伸到系统栏区域。


内容的提问来源于stack exchange,提问作者Cihan Çelebi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.08 16:48:01