As Adrian Grygutis pointed out on the comment, in 1.0.0
, TextField
has a parameter colors
. You could customize your TextField
by calling TextFieldDefaults.textFieldColors(...)
with the parameter you want to change.
TextField(
...
colors: TextFieldColors = TextFieldDefaults.textFieldColors(textColor = Color.White),
) {
As for theming, and if you want to avoid calling every time:
ProvideTextStyle(TextStyle(color = Color.White)) {
TextField(
...
)
}
You could create a composable with your own set of TextFieldColors
and add it as a parameter in your TextField
. You could for instance, have all colors as white:
@Composable
fun MyAppTextFieldColors(
textColor: Color = Color.White,
disabledTextColor: Color = Color.White,
backgroundColor: Color = Color.White,
cursorColor: Color = Color.White,
errorCursorColor: Color = Color.White,
...
) = TextFieldDefaults.textFieldColors(
textColor = textColor,
disabledTextColor = disabledTextColor,
backgroundColor = backgroundColor,
cursorColor = cursorColor,
errorCursorColor = errorCursorColor,
...
)
To avoid calling this in every TextField
, you can then create a custom MyAppTextField
for your app that calls the default TextField
with your custom TextFieldColors
as a default parameter:
@Composable
fun MyAppTextField(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
...
colors: TextFieldColors = MyAppTextFieldColors(),
) {
TextField(
value = value,
onValueChange = onValueChange,
modifier = modifier,
...
colors = colors,
)
}
That way, you would only need to call MyAppTextField
. It's a good way to override colours inherited from the theme if needed.