Tunahan
Tunahan

Reputation: 444

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.

Upvotes: 4

Views: 1691

Answers (3)

Arpit Patel
Arpit Patel

Reputation: 8067

You can use LocalTextStyle property to replace text color.

 textStyle = LocalTextStyle.current.copy(color = Gray)

Upvotes: 2

Gabriele Mariotti
Gabriele Mariotti

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
        )
    }

enter image description here

Upvotes: 1

Dan Artillaga
Dan Artillaga

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

Related Questions