Home > Enterprise >  Android Jetpack Compose: Can't find OutlinedTextField in Empty Compose Activity (Material3)
Android Jetpack Compose: Can't find OutlinedTextField in Empty Compose Activity (Material3)

Time:12-09

When I create new project and select "Empty Compose Activity (Material3)", I can't use OutlinedTextField.

OutlinedTextField not shown

When I create new project and select "Empty Compose Activity" it's Ok OutlinedTextField shown

Why there is a different and how can I fix this?

CodePudding user response:

In your build.gradle upgrade the Material3 dependency to the latest as below.

implementation 'androidx.compose.material3:material3:1.0.1'

This shows OutlinedTextField in the project.

You must also add the @OptIn(ExperimentalMaterial3Api::class) to your function as below.

@OptIn(ExperimentalMaterial3Api::class)
OutlinedTextField(
    value = text,
    onValueChange = { text = it },
)
  • Related