Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutlinedTextField's Text Color Does Not Change When Disabled

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

        )
    }

WhatI I want to make this.

WhatsHappening It's the my code's result. As you can see border is disabled but the text is still enabled.

like image 656
Tunahan Avatar asked Nov 01 '25 18:11

Tunahan


2 Answers

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),
    ...
)
like image 136
danartillaga Avatar answered Nov 03 '25 08:11

danartillaga


You can use LocalTextStyle property to replace text color.

 textStyle = LocalTextStyle.current.copy(color = Gray)
like image 38
Arpit Patel Avatar answered Nov 03 '25 10:11

Arpit Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!