TargetSdk 36: edge-to-edge, back button and tablet fixes

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

TargetSdk 36: edge-to-edge, back button and tablet fixes

Originally published on AppRanker. Google Play has refused app updates below target API 36 since the one-time extension ended on November 1, 2026 — and bumping targetSdk is the easy part. Target Android 16 and three production behaviors change: layouts draw under the system bars, the back button stops calling onBackPressed(), and tablets drop your portrait lock. Nothing fails a build — the bugs arrive later, as screenshots and one-star reviews.

本文最初发布于 AppRanker。自 2026 年 11 月 1 日一次性延期结束以来,Google Play 已拒绝目标 API 低于 36 的应用更新,而提升 targetSdk 只是最简单的一步。当目标版本设为 Android 16 时,会有三种生产环境行为发生变化:布局会在系统栏下方绘制,返回按钮不再调用 onBackPressed(),且平板电脑会忽略你的竖屏锁定设置。这些都不会导致构建失败,但漏洞随后会以截图和一星差评的形式出现。

What Play enforces now

Google Play 目前的强制要求

RuleDateWhat it means
New apps and updates must target Android 16 (API 36) or higherAug 31, 2026A release below targetSdk 36 is rejected
One-time extension requested in Play ConsoleEnded Nov 1, 2026Extra time, never a renewal
Existing apps must target API 35 or higherOngoingBelow that, new users on newer Android can’t install
Wear OS / Android Automotive OSAug 31, 2026API 35 is enough
Android TV / Android XRAug 31, 2026API 34 is enough
规则日期含义
新应用和更新必须以 Android 16 (API 36) 或更高版本为目标2026 年 8 月 31 日低于 targetSdk 36 的版本将被拒绝
在 Play 管理中心申请的一次性延期已于 2026 年 11 月 1 日结束额外时间,不可续期
现有应用必须以 API 35 或更高版本为目标持续进行低于此版本,新 Android 设备上的新用户无法安装
Wear OS / Android Automotive OS2026 年 8 月 31 日API 35 即可
Android TV / Android XR2026 年 8 月 31 日API 34 即可

Permanently private, org-internal apps are exempt. The requirement gates releases, not listings: an app targeting 35 stays installable, it just cannot receive updates. Confirm your live number first: Play Console’s App bundle explorer shows each bundle’s target SDK, or locally: aapt2 dump badging app-release.apk | grep -o "targetSdkVersion:'[0-9]*'"

永久私有的组织内部应用可获豁免。该要求限制的是发布而非上架:目标版本为 35 的应用仍然可以安装,只是无法接收更新。请先确认你的线上版本号:Play 管理中心的 App Bundle 资源管理器会显示每个 Bundle 的目标 SDK,或者在本地运行:aapt2 dump badging app-release.apk | grep -o "targetSdkVersion:'[0-9]*'"。

Flutter 3.38+ already targets 36 by default, and the React Native template does from 0.81 — teams often hit the changes below right after a routine framework upgrade.

Flutter 3.38+ 默认已将目标版本设为 36,React Native 模板从 0.81 版本开始也已如此设置——开发团队通常在常规框架升级后会立即遇到以下变化。

Edge-to-edge: content lands under the system bars

全屏显示:内容延伸至系统栏下方

For targetSdk 36 apps, android:windowOptOutEdgeToEdgeEnforcement is ignored on Android 16: the app draws behind the status and navigation bars, and anything unpadded gets covered. Developers report the ActionBar shifted down, bottom sheets gaining padding in landscape, and adjustPan forms stacking at the top when the keyboard opens.

对于 targetSdk 36 的应用,android:windowOptOutEdgeToEdgeEnforcement 在 Android 16 上会被忽略:应用会在状态栏和导航栏后方绘制,任何未设置内边距的内容都会被遮挡。开发者反馈 ActionBar 会下移,底部表单(bottom sheets)在横屏时会出现内边距,且当键盘弹出时,adjustPan 模式下的表单会堆叠在顶部。

In Views: Delete windowOptOutEdgeToEdgeEnforcement from every theme — it no longer protects you on Android 16 and hides the problem on Android 15 test devices. Call enableEdgeToEdge() per activity, drop the deprecated setStatusBarColor(), and pad content with system bar plus display cutout insets:

在 Views 中:从所有主题中删除 windowOptOutEdgeToEdgeEnforcement——它在 Android 16 上已不再起作用,且会在 Android 15 测试设备上掩盖问题。在每个 Activity 中调用 enableEdgeToEdge(),弃用已过时的 setStatusBarColor(),并使用系统栏和显示缺口(display cutout)的内边距来填充内容:

ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, insets ->
    val bars = insets.getInsets(
        WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
    )
    view.updatePadding(bars.left, bars.top, bars.right, bars.bottom)
    WindowInsetsCompat.CONSUMED
}

On screens with text fields, use WindowInsetsCompat.Type.ime() rather than adjustPan or adjustResize; for light backgrounds set WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = true.

在包含文本字段的屏幕上,使用 WindowInsetsCompat.Type.ime() 而不是 adjustPan 或 adjustResize;对于浅色背景,请设置 WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = true。

Compose: pass the Scaffold content padding down, or use Modifier.safeDrawingPadding() / Modifier.imePadding(). Flutter: wrap screens in SafeArea or read MediaQuery.paddingOf(context) — Flutter warns the Android 16 opt-out can crash. React Native: replace <SafeAreaView> with react-native-safe-area-context; StatusBar’s backgroundColor and translucent change, and 0.81’s edgeToEdgeEnabled Gradle property matches older Android.

Compose:向下传递 Scaffold 内容内边距,或使用 Modifier.safeDrawingPadding() / Modifier.imePadding()。Flutter:使用 SafeArea 包裹屏幕或读取 MediaQuery.paddingOf(context)——Flutter 警告称 Android 16 的退出机制可能会导致崩溃。React Native:将 <SafeAreaView> 替换为 react-native-safe-area-context;StatusBar 的 backgroundColor 和 translucent 属性会有所变化,且 0.81 版本的 edgeToEdgeEnabled Gradle 属性可兼容旧版 Android。

Predictive back: onBackPressed() goes silent

预测性返回:onBackPressed() 失效

Predictive back is on by default for targetSdk 36 apps: onBackPressed() is never called and KEYCODE_BACK never dispatched, so custom back logic silently stops running. The classic victim is a WebView wrapper that overrode onBackPressed() to call webView.goBack() — back now exits the app instead of going back one page.

对于 targetSdk 36 的应用,预测性返回功能默认开启:onBackPressed() 不再被调用,KEYCODE_BACK 也不会被分发,因此自定义的返回逻辑会静默失效。典型的受害者是重写了 onBackPressed() 以调用 webView.goBack() 的 WebView 封装器——现在点击返回会直接退出应用,而不是返回上一页。

Move the logic to OnBackPressedCallback (AndroidX Activity 1.6.0+), enabled only while your app needs to intercept back, so the system animation plays the rest of the time. For a WebView, tie it to page history:

请将逻辑迁移至 OnBackPressedCallback (AndroidX Activity 1.6.0+),仅在应用需要拦截返回操作时启用,以便在其余时间播放系统动画。对于 WebView,请将其与页面历史记录绑定:

class BrowserActivity : AppCompatActivity() {
    private val webBack = object : OnBackPressedCallback(false) {
        override fun handleOnBackPressed() {
            webView.goBack()
        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        onBackPressedDispatcher.addCallback(this, webBack)
        webView.webViewClient = object : WebViewClient() {
            override fun doUpdateVisitedHistory(view: WebView, url: String?, isReload: Boolean) {
                webBack.isEnabled = view.canGoBack()
            }
        }
    }
}

With no history, the callback is disabled and back leaves the screen with the system animation. Compose: BackHandler(enabled = ...), or PredictiveBackHandler to animate with the gesture. Flutter: PopScope with onPopInvokedWithResult replaces the deprecated WillPopScope; predictive back transitions are on by default in MaterialApp since 3.38. React Native: BackHandler still works in 0.81, but native modules overriding onBackPressed() must move to OnBackPressedDispatcher. If you cannot finish in time, android:enableOnBackInvokedCallback="false" on the <application> or a single <activity> is a documented temporary opt-out — a stopgap, not a fix.

当没有历史记录时,回调被禁用,返回操作会通过系统动画离开屏幕。Compose:使用 BackHandler(enabled = ...) 或 PredictiveBackHandler 来实现手势动画。Flutter:使用带有 onPopInvokedWithResult 的 PopScope 替换已过时的 WillPopScope;自 3.38 版本起,MaterialApp 默认开启预测性返回过渡。React Native:BackHandler 在 0.81 版本中仍可使用,但重写 onBackPressed() 的原生模块必须迁移至 OnBackPressedDispatcher。如果你无法及时完成迁移,在 <application> 或单个 <activity> 上设置 android:enableOnBackInvokedCallback="false" 是官方记录的临时退出方案——这只是权宜之计,而非根本修复。

Tablets and foldables ignore your orientation lock

平板电脑和折叠屏设备会忽略你的屏幕方向锁定

On displays with a smallest width of 600dp or more, Android 16 ignores android:screenOrientation, resizeableActivity="false", the min/max aspect ratio attributes and setRequestedOrientation() for targetSdk 36 apps: a portrait-only app stretches to fill a landscape tablet or an open foldable instead of being letterboxed. Phones are unaffected — the change applies only at 600dp and up.

在最小宽度为 600dp 或以上的显示屏上,对于 targetSdk 36 的应用,Android 16 会忽略 android:screenOrientation、resizeableActivity="false"、最小/最大纵横比属性以及 setRequestedOrientation():仅支持竖屏的应用会拉伸以填满横屏平板电脑或展开的折叠屏,而不是显示黑边。手机不受影响——此变化仅适用于 600dp 及以上的设备。

Games are exempt via android:appCategory, and users can pick the app’s default in the device’s aspect ratio settings. A temporary opt-out exists (android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY set to true), but Google’s Android 17 notes say it disappears for apps targeting API 37. The lasting fix is making main screens survive rotation and resizing:

游戏可通过 android:appCategory 获得豁免,用户可以在设备的纵横比设置中选择应用的默认显示方式。目前存在一个临时退出方案(将 android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY 设置为 true),但 Google 的 Android 17 说明指出,该方案在目标 API 37 的应用中将失效。长久的修复方案是确保主屏幕能够适应旋转和调整大小:

Keep screen state in a ViewModel or saved state so rotation does not reset a form, a video or a canvas. Test on Pixel Tablet and Pixel Fold emulator images in both orientations, and drag the window in multi-window mode. Cap the width of text-heavy layouts so lines do not run across a 12-inch screen. Check camera previews first — they look stretched or sideways most often. Smaller changes that still bite: elegantTextHeight.

将屏幕状态保存在 ViewModel 或已保存的状态中,以便旋转不会重置表单、视频或画布。在 Pixel Tablet 和 Pixel Fold 模拟器镜像上测试两种方向,并在多窗口模式下拖动窗口。限制文本密集型布局的宽度,以免行文横跨 12 英寸屏幕。首先检查相机预览——它们最容易出现拉伸或横向显示的问题。其他仍会造成影响的小改动包括:elegantTextHeight。