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

Flutter应用插屏广告无法全屏覆盖问题求助

Flutter插屏广告无法全屏覆盖屏幕顶部的解决方案

针对你在Pixel 6 Pro API 34模拟器上遇到的插屏广告无法覆盖顶部的问题,提供以下几个可行的解决方向:

1. 调整沉浸式模式调用时机

你已经使用了setImmersiveMode(true),可以尝试将调用时机移到广告显示前,确保配置生效:

void _showInterstitialAd() {
    if (_interstitialAd == null) {
      print('Warning: attempt to show interstitial before loaded.');
      return;
    }
    // 在显示广告前再次设置沉浸式模式
    _interstitialAd!.setImmersiveMode(true);
    _interstitialAd!.fullScreenContentCallback = FullScreenContentCallback(
      onAdShowedFullScreenContent: (InterstitialAd ad) =>
          print('ad onAdShowedFullScreenContent.'),
      onAdDismissedFullScreenContent: (InterstitialAd ad) {
        print('$ad onAdDismissedFullScreenContent.');
        ad.dispose();
        _createInterstitialAd();
      },
      onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) {
        print('$ad onAdFailedToShowFullScreenContent: $error');
        ad.dispose();
        _createInterstitialAd();
      },
    );
    _interstitialAd!.show();
    _interstitialAd = null;
  }

2. 适配Android 14(API 34)全屏特性

API 34对系统UI和全屏行为有更新,可通过以下配置调整:

  • 修改android/app/src/main/AndroidManifest.xml中对应Activity的属性,添加全屏相关配置:
<activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
    android:theme="@style/LaunchTheme"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
    android:hardwareAccelerated="true"
    android:windowSoftInputMode="adjustResize"
    android:windowFullscreen="true"
    android:windowTranslucentStatus="true">
  • 或者在android/app/src/main/res/values/styles.xml中设置全屏主题:
<style name="LaunchTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

3. 手动控制系统状态栏显示

在显示广告前手动隐藏系统状态栏,广告关闭后恢复:

import 'package:flutter/services.dart';

void _showInterstitialAd() async {
    if (_interstitialAd == null) {
      print('Warning: attempt to show interstitial before loaded.');
      return;
    }
    // 隐藏状态栏和导航栏
    await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
    
    _interstitialAd!.fullScreenContentCallback = FullScreenContentCallback(
      onAdShowedFullScreenContent: (InterstitialAd ad) =>
          print('ad onAdShowedFullScreenContent.'),
      onAdDismissedFullScreenContent: (InterstitialAd ad) {
        print('$ad onAdDismissedFullScreenContent.');
        // 恢复系统UI显示
        SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
        ad.dispose();
        _createInterstitialAd();
      },
      onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) {
        print('$ad onAdFailedToShowFullScreenContent: $error');
        // 恢复系统UI显示
        SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
        ad.dispose();
        _createInterstitialAd();
      },
    );
    _interstitialAd!.show();
    _interstitialAd = null;
  }

4. 确认插件版本兼容性

执行flutter pub upgrade google_mobile_ads更新插件,确保使用的google_mobile_ads版本适配Android 14(API 34)的特性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 21:23:29