Alexandru Gheorghe
Alexandru Gheorghe

Reputation: 371

Unresolved reference: enableEdgeToEdge in onCreate function JetPack Compose

I'm following Android Basic Course and the solution code provided has enableEdgeToEdge() function call in onCreate() in MainActivity. When I use this line of code, I get Unresolved reference: enableEdgeToEdge error.

Couldn't find a solution to it despite trying multiple imports and looking on the Internet for the issue. Any ideas on how to fix this?

Code available on GitHub: https://github.com/alghe-global/Kotlin/blob/4a25e707d4efc3edf09c7f637635adec8f6e876b/AndroidBasicsCourse/TipTime/app/src/main/java/com/example/tiptime/MainActivity.kt#L36

N.B. Solution code from Google is available @ https://github.com/google-developer-training/basic-android-kotlin-compose-training-tip-calculator/blob/29dddab0d5d911f1607bc5602249f89012f4d45e/app/src/main/java/com/example/tiptime/MainActivity.kt#L54

Trying to import androidx.activity.enableEdgeToEdge and call enableEdgeToEdge() in onCreate(...) gives the error Unresolved reference: enableEdgeToEdge on both the import enableEdgeToEdge and the function call enableEdgeToEdge()

Upvotes: 13

Views: 7242

Answers (3)

Chirag Thummar
Chirag Thummar

Reputation: 3232

The Jetpack Compose team has introduced the enableEdgeToEdge() to avoid boilerplate code related to system bars like the status bar, navigation bar, etc.

You need to update to the latest version of implementation('androidx.activity:activity:1.8.1') to use enableEdgeToEdge features.

Upvotes: 18

vvvvv
vvvvv

Reputation: 31720

Adding implementation("androidx.activity:activity:1.8.1") to build.gradle.kts (Module :app) allowed me to use enableEdgeToEdge.


This answer was posted as an edit to the question (SOLVED) Unresolved reference: enableEdgeToEdge in onCreate function JetPack Compose by the OP Alexandru Gheorghe under CC BY-SA 4.0.

Upvotes: 0

Surya Pratap
Surya Pratap

Reputation: 93

For people using Jetpack Compose

-> update activity-compose dependency to 1.9.0 or newer

Upvotes: 1

Related Questions