How to Properly Target Android 15 (API Level 35) and Handle Edge-to-Edge UI Changes

Google Play now requires all apps to target Android 15 (API level 35) or higher. While this update is essential for staying compliant and accessing new platform features, it also introduces layout challenges—particularly with the system bars and app bars.

In this blog post, I’ll walk you through the step-by-step process to update your project and handle edge-to-edge layout issues that might arise.


Before   


After 








✅ Step 1: Update Your Target SDK to Android 15

In your app's build.gradle file, update the target SDK version:

gradle
android { compileSdk 35 defaultConfig { targetSdk 35 } }

After updating, you might notice that your AppBar overlaps with the system status bar. This is due to Android’s edge-to-edge layout behavior, which changes how content interacts with system bars.


🛠️ Step 2: Enable Edge-to-Edge Display in Your Activity

If you’re using a BaseActivity or a regular Activity, add the following code before setContentView() in your onCreate() method:

kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { WindowCompat.setDecorFitsSystemWindows(window, false) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent) WindowCompat.getInsetsController(window, window.decorView)?.apply { isAppearanceLightStatusBars = true } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.navigationBarColor = ContextCompat.getColor(this, android.R.color.transparent) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { WindowCompat.getInsetsController(window, window.decorView)?.apply { isAppearanceLightNavigationBars = true } } } }

This ensures that your layout can extend behind system bars while maintaining proper light/dark contrast.


🧩 Step 3: Apply Window Insets After setContentView()

To prevent content overlap and ensure your AppBar or Toolbar respects system insets, apply the following logic after setContentView():

kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { handleEdgeToEdgeInsets() }

Then define the handleEdgeToEdgeInsets() function like this:

kotlin
private fun handleEdgeToEdgeInsets() { ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets -> val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) val appBar = view.findViewById<View>(R.id.appbar) val toolbar = view.findViewById<View>(R.id.toolbar) when { appBar != null -> { appBar.setPadding( appBar.paddingLeft, insets.top, appBar.paddingRight, appBar.paddingBottom ) } toolbar != null -> { toolbar.setPadding( toolbar.paddingLeft, insets.top, toolbar.paddingRight, toolbar.paddingBottom ) } else -> { view.setPadding( view.paddingLeft, insets.top, view.paddingRight, view.paddingBottom ) } } windowInsets } }

🎯 Final Thoughts

Migrating to Android 15 (API level 35) is crucial—but ensuring your UI looks great on modern devices is just as important. By properly handling system insets and enabling edge-to-edge mode, you’ll deliver a polished and immersive experience.

Have questions or facing issues during the migration? Drop them in the comments!


Comments

  1. Techlancers stands out as a trusted name in app development dubai, providing customized solutions for startups, SMEs, and enterprises. Our team ensures every app is innovative, reliable, and aligned with business goals, making us the preferred partner for mobile solutions in the region.

    ReplyDelete

Post a Comment