Another failing attempt to implement Edge to Edge in an old Android app. Documentation says I can call
ComponentActivity.enableEdgeToEdge() or WindowCompat.enableEdgeToEdge(getWindow())
but the compiler says both functions do not exist.
The API documentation says that the first requires some parameters, but the second should be valid. When I pull up the source code for androidx.core.view.WindowCompat at cs.android.com, it shows the enableEdgeToEdge() function I am trying to call. But when I pull up the source for the same module within AndroidStudio, I get a completely different source which lacks that function.
Relevent excerpts from Android.xml
compileSdk 36
implementation 'androidx.core:core:1.16.0'
I tried invalidating caches and restarting AndroidStudio with no success.
So what else can I try?
Thx for any assistance.
Depending on your target SDK and androidx.core:core version, there are two ways to enable edge-to-edge:
For Android 15 (API 35) or lower:
Keep using older API (call it before super.onCreate()).
For Java: EdgeToEdge.enable(this)
For Kotlin: enableEdgeToEdge() (extension function for ComponentActivity)
For Android 16 (API 36) or higher:
You can use new API WindowCompat.enableEdgeToEdge() (call it after super.onCreate())
Note: You will require dependency androidx.core:core:1.17.0 or higher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With