fix: set up edge-to-edge without Android 15's deprecated window APIs

Play's release dashboard listed Window.setStatusBarColor, Window.setNavigationBarColor and
LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES under "deprecated APIs or parameters for
edge-to-edge", starting in vr.b, xr.b and zr.b. None of those are app code: the R8 mapping
resolves vr/xr/zr to androidx.activity's EdgeToEdgeApi26/29/35, and a dexdump of the release
DEX finds six calls to the two colour setters, all reached through
ComponentActivity.enableEdgeToEdge(). Its per-API implementations still paint the bar scrims
(API 21/26/29) and select SHORT_EDGES on API 28/29, which Android 15 deprecates for apps
targeting SDK 35+.

MainActivity now calls ui/theme/EdgeToEdge.applyEdgeToEdge() instead. It keeps the parts that
still matter - setDecorFitsSystemWindows(false), navigation-bar contrast off, cutout mode
"always" on API 30+, and light/dark bar icons read from the system night mode - and drops the
scrim writes. The transparent bars continue to come from the XML theme, which does not
compile into a DEX call, so pre-35 devices look unchanged; API 28/29 keep the platform
default cutout mode rather than the deprecated SHORT_EDGES. The insets handling in
ScannerScreen (TopAppBar and navigationBarsPadding) is untouched.

Verified on the connected Android 12 device in both light and dark mode: the window reports
layoutInDisplayCutoutMode=always and the expected LIGHT_STATUS_BAR/LIGHT_NAVIGATION_BAR
flags, and the screenshots show content behind both bars with readable icons. The rebuilt
release APK and AAB contain zero references to setStatusBarColor/setNavigationBarColor and
no androidx.activity.EdgeToEdge classes; testDebugUnitTest and lintDebug pass (only the
pre-existing OldTargetApi warning). CHANGELOG records the change.
This commit is contained in:
2026-10-18 16:48:02 +02:00
parent 7b92da4f8b
commit bb250d1675
3 changed files with 72 additions and 2 deletions
@@ -3,18 +3,20 @@ package de.softwareapp_hb.fotodup.finder
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import de.softwareapp_hb.fotodup.finder.ui.scanner.ScannerScreen
import de.softwareapp_hb.fotodup.finder.ui.theme.FotoDupTheme
import de.softwareapp_hb.fotodup.finder.ui.theme.applyEdgeToEdge
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
// AndroidX's enableEdgeToEdge() would do this too, but it still uses APIs that are
// deprecated on Android 15; see applyEdgeToEdge() for the details.
applyEdgeToEdge()
setContent {
FotoDupTheme {
Surface(
@@ -0,0 +1,55 @@
package de.softwareapp_hb.fotodup.finder.ui.theme
import android.app.Activity
import android.content.res.Configuration
import android.os.Build
import android.view.WindowManager
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
/**
* Draws the activity edge-to-edge using only window APIs that are still current on Android 15.
*
* `ComponentActivity.enableEdgeToEdge()` (androidx.activity 1.13.0) still calls
* `Window.setStatusBarColor()` and `Window.setNavigationBarColor()` in its API 21/26/29
* implementations, and it sets `LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES` on API 28/29. All
* three are deprecated for apps targeting SDK 35 and therefore appear in Play Console as
* "Your app uses deprecated APIs or parameters for edge-to-edge".
*
* The window itself is already transparent because of the theme, so the colour-scrim half of
* `enableEdgeToEdge()` is unnecessary. What remains is letting the window lay out behind the
* system bars, keeping the navigation-bar scrim off, and choosing light or dark bar icons for
* the current theme.
*
* Call this from `Activity.onCreate()`, after `super.onCreate()` and before setting content.
*/
fun Activity.applyEdgeToEdge() {
// Lay out behind the status and navigation bars instead of letting the decor view inset
// them. On API 35+ this is a no-op: the platform already enforces edge-to-edge there.
WindowCompat.setDecorFitsSystemWindows(window, false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// The navigation bar is transparent (see the theme), and without this Android 10+ draws
// its own translucent contrast scrim over the gesture/button area.
window.isNavigationBarContrastEnforced = false
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Allow the app to draw into the display cutout on every edge. API 28/29 would need the
// now-deprecated SHORT_EDGES mode for that, so those versions keep the platform default
// instead; Android 15 ignores the mode because edge-to-edge is mandatory there.
window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
}
}
val darkTheme = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES
WindowInsetsControllerCompat(window, window.decorView).apply {
// Dark icons on a light background and light icons on a dark one — the same system
// night-mode flag that drives FotoDupTheme.
isAppearanceLightStatusBars = !darkTheme
isAppearanceLightNavigationBars = !darkTheme
}
}