TextField(value = "", onValueChange = {},
leadingIcon = {
Icon( Icons.Default.Search, contentDescription = "")
},
placeholder = {
Text(text = stringResource(id = R.string.placeholder_search))
},
colors = TextFieldDefualts.textFieldColors(),
modifier = modifier
.heightIn(min = 56.dp)
.fillMaxWidth())
}
And also it show error message as "This material API is experimental and is likely to change or to be removed in the future."
TextFieldDefaults.textFieldColors()
is deprecated and asked me to move it to in Material3 library and after moving to material3, still it shows textFieldColors()
deprecated.. Any help would be a great help
dependencies added in build.gradle
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2023.10.01')
implementation(composeBom)
androidTestImplementation(composeBom)
implementation 'androidx.core:core-ktx:1.12.0'
implementation "androidx.compose.ui:ui"
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.material3:material3-window-size-class:1.1.2'
implementation "androidx.compose.material:material-icons-extended"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation "com.google.android.material:material:1.11.0"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
debugImplementation "androidx.compose.ui:ui-tooling"
}
2
Answers
As
TextFieldDefaults.textFieldColors()
deprecated in Material3 library. we need to migrate to the following call for applying colors in Compose TextField asTextFieldDefaults.colors()
And instead of
backgroundColor =
as follows :we need to migrate to as follows :
It’s not necessary when using Material3.
TextFieldDefaults.textFieldColors()
, leverage Material3’s ColorScheme API to create aTextFieldColors
instance:See here –