I don’t know what happened even though I copy exactly the code from Android Developer Team official Youtube. The textfield
turns red BUT when I remove color = Color.black
in SearchBar
composable, everything works fine. Help me
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MySootheApp()
}
}
}
@Composable
fun SearchBar(
modifier: Modifier = Modifier
) {
TextField(
value = "",
onValueChange = {},
color = Color.Black,
leadingIcon = { Icon(Icons.Default.Search , contentDescription = null) },
placeholder = { Text(text = "Search Here") },
modifier = Modifier
.heightIn(min = 56.dp)
.fillMaxWidth(),
)
}
I have tried to remove color = Color.Black
and it works fine
3
Answers
You can manage color of
TextField
like this in jetpack composeYour
TextField
background shows red because you wrap theSearchBar
composable usingSurface
composable. Which take Surface color of red set ontheme.kt
file.If you want to change background color of
TextField
.If you want to change the color in the M2
TextField
you can use:The
color
attribute doesn’t exist in theTextField
.