Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidStudio library problem does not allow call to WindowCompat.enableEdgeToEdge()

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.

like image 914
kencorbin Avatar asked Jan 25 '26 08:01

kencorbin


1 Answers

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

like image 174
Peter Avatar answered Jan 26 '26 23:01

Peter