Reputation: 444
I modified my textfield according to this article. TextFieldDefaults
It is perfectly fine it is enabled but if i disable it textcolor is not changing like OutlinedTextField. It's textcolor still behave like it's enabled. What should i do ?
val colors = TextFieldDefaults.outlinedTextFieldColors()
val text = "+56"
BasicTextField(
value = text,
onValueChange = {},
interactionSource = interactionSource,
enabled = false,
singleLine = true,
textStyle = TextStyle.Default,
modifier = modifier
.width(IntrinsicSize.Min)
.layoutId("country_code"),
){
TextFieldDefaults.OutlinedTextFieldDecorationBox(
value = "+56",
enabled = false,
singleLine = true,
innerTextField = it,
visualTransformation = VisualTransformation.None,
interactionSource = interactionSource,
colors = colors
)
}
It's the my code's result. As you can see border is disabled but
the text is still enabled.
Upvotes: 4
Views: 1691
Reputation: 8067
You can use LocalTextStyle
property to replace text color.
textStyle = LocalTextStyle.current.copy(color = Gray)
Upvotes: 2
Reputation: 365028
It seems a bug.
As workaround you can use something like:
val colors = TextFieldDefaults.outlinedTextFieldColors()
val enabled = false
val textColor = colors.textColor(enabled).value
val mergedTextStyle = TextStyle.Default.merge(TextStyle(color = textColor))
BasicTextField(
//your implementation
textStyle = mergedTextStyle,
) {
TextFieldDefaults.OutlinedTextFieldDecorationBox(
//your implementation
)
}
Upvotes: 1
Reputation: 1955
Set the color of your BasicTextField
's textStyle
to the color from TextFieldDefaults.outlinedTextFieldColors()
val colors = TextFieldDefaults.outlinedTextFieldColors()
val enabled = false
OutlinedTextField(
textStyle = TextStyle.Default.copy(color = colors.textColor(enabled).value),
...
)
Upvotes: 4