OutlinedTextField placeholder, not changing color in Jetpack Compose

40 Views Asked by At

I've been trying to get the placeholder text inside of an OutlinedTextField to change color and it is just staying black, no matter what I do. I am using M3 theme and components. I can get everything else to change (text color, border color, etc), just not the placeholder. In my Color.kt file I define all the colors, one of them being onSurface...

val md_theme_dark_onSurface = Color(red = 140, green = 207, blue = 242)

Then in my LoginView.kt I am trying to use that to tell the placeholder what color to be...

val textFieldColor = OutlinedTextFieldDefaults.colors(
  focusedPlaceholderColor = MaterialTheme.colorScheme.onSurface,
  unfocusedPlaceholderColor = MaterialTheme.colorScheme.onSurface
)

Then set the colors of the outlined text field...

OutlinedTextField(
  value = uiState.username,
  keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
  onValueChange = { viewModel.setUsername(it) },
  placeholder = { Text("Username") },
  leadingIcon = {
    Image(painter = painterResource(id = R.drawable.user), contentDescription = null)
  },
  colors = textFieldColor
)

One would think that would change the placeholder in the text field, but it does not. I still get a black placeholder. The border and image are correctly colored and change when focused/unfocused but the placeholder stays black, even in Dark theme.

enter image description here

What can I try next?

1

There are 1 best solutions below

0
sasikumar On

use this code, tested its working

   OutlinedTextField(
        value ="hello",
        keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
        onValueChange = {"ssss"},
        placeholder = { Text("Username") },
        leadingIcon = {
            Image(painter = painterResource(id = R.drawable.ic_settings_black_24dp), contentDescription = null)
        },
        colors = TextFieldDefaults.colors(
            focusedPlaceholderColor = Color.Red,
            unfocusedTextColor = Color.Green

        )
    )