How to change the TextField text color in Jetpack ...
# compose
s
How to change the TextField text color in Jetpack Compose?
Copy code
val username = remember { mutableStateOf(TextFieldValue()) }
TextField(
    modifier = Modifier.fillMaxWidth().padding(16.dp, 0.dp, 16.dp, 0.dp)
        .constrainAs(et_username) {
            top.linkTo(title.bottom, margin = 30.dp)
        },
    label = { Text(text = "Username") },
    leadingIcon = { Icon(Icons.Outlined.Person) },
    textStyle = typography.subtitle1,
    backgroundColor = MaterialTheme.colors.background,
    value = username.value,
    onValueChange = { username.value = it }
)
d
You'll have to write a custom
VisualTransformation
I think.
k
I guess wrapping the textfield inside a
Surface
with required color as
contentColor
might also work. Or probably there's
AmbientContentColor
which you can provide with desired color using something like Providers(
AmbientContentColor
provides <your color>) {...}
s
@Dominaezzz @Kshitij Patil I have achieved using Text Style in Text Field
val username = remember { mutableStateOf(TextFieldValue()) }
TextField(
modifier = Modifier.fillMaxWidth().padding(16.dp, 0.dp, 16.dp, 0.dp)
.constrainAs(et_username) {
top.linkTo(title.bottom, margin = 30.dp)
},
label = { Text(text = "Username") },
leadingIcon = { Icon(Icons.Outlined.Person) },
textStyle = TextStyle(
color = MaterialTheme.colors.onPrimary,
fontSize = TextUnit.Sp(16)
),
backgroundColor = MaterialTheme.colors.background,
value = username.value,
onValueChange = { username.value = it }
Copy code
)