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

如何在Android SDK 35后禁用边缘到边缘显示行为?

解决Capacitor v7(Android SDK 35)导航栏遮挡应用底部问题

完全可以通过调整styles.xml和activity_main.xml解决这个问题,SDK 35对系统UI的布局规则做了更新,以下是具体调整方案:

1. 修改res/values/styles.xml

找到你的应用主题(通常是AppTheme),添加或修改以下属性:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- 允许应用绘制系统栏背景,确保内容能正确适配导航栏 -->
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <!-- 禁用半透明导航栏,避免内容穿透 -->
    <item name="android:windowTranslucentNavigation">false</item>
    <!-- 让应用内容适配屏幕刘海/挖孔区域,同时避开导航栏 -->
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    <!-- 可选:设置导航栏颜色,和应用主题匹配 -->
    <item name="android:navigationBarColor">@color/ionic_background</item>
</style>

2. 调整res/layout/activity_main.xml

找到布局中的WebView节点(或根布局),添加android:fitsSystemWindows="true"属性,确保WebView自动适配系统导航栏的高度:

<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:fitsSystemWindows="true">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

原理说明

SDK 35强化了系统UI的布局边界检查,fitsSystemWindows="true"会让布局自动预留出状态栏和导航栏的空间,而windowLayoutInDisplayCutoutMode确保应用不会被屏幕挖孔或刘海遮挡,同时导航栏不再穿透应用内容。

如果调整后仍有问题,可结合Ionic的ion-content组件的fullscreen属性,或在Vue代码中通过Platform API获取导航栏高度,手动给底部元素添加padding,但通过上述XML调整已经能解决绝大多数场景的遮挡问题。

内容的提问来源于stack exchange,提问作者Lucien Dubois

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 21:07:08