5

I want to change the background color of a TextField in Jetpack Compose, but nothing seems to work.

TextField

I have tried setting Modifier.background(color = Color.Transparent), but it does not work (color does not change). Also, I have tried using both colors = TextFieldDefaults.textFieldColors(...) and colors = TextFieldDefaults.colors(...), as suggested in this question, but none of them have backgroundColor or any other parameter related to background (in Material3). I have also tried this approach, but it does not work either.

1 Answer 1

9

The TextField's colors are defined by the colors parameter. There are a lot of different colors that can be customized, but the ones you need are the container colors:

TextField( colors = TextFieldDefaults.colors( focusedContainerColor = Color.Green, unfocusedContainerColor = Color.Blue, disabledContainerColor = Color.Gray, errorContainerColor = Color.Red, ), ) 

Set them as you like and omit those for that you want to use the default colors.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.