I have an OutlinedTextField
and I want it to have a white background but only the TextField. The thing is, when I add modifier = Modifier.background(color = AppWhite)
, not only the textField is white, but also what’s surrounding it (see first attached image) and, when I remove the modifier, everything is green (like the second image).
This is my Composable:
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
OutlinedTextField(
shape = RoundedCornerShape(20.dp),
modifier = Modifier.background(color = AppWhite),
value = searchText,
onValueChange = { searchText = it },
label = {
Text(stringResource(R.string.searchHint))
},
.
.
.
Image(
modifier = Modifier.padding(top = 8.dp),
painter = painterResource(R.drawable.isotype_white),
contentDescription = null
)
How can I set only the TextField’s background to white without having the extra white outside it??
2
Answers
You can set
colors
for yourOutlinedTextField
container usingcolors
parameter like this:You have the extra white background because you are setting the modifier background color to the whole OutlinedTextField (which is a big rectangle). For your purpose, you need to apply your change only on the part of the OutlinedTextField you want (here only the text).
As mentioned in the response above, use the colors for the OutlinedTextField should fix the issue.
OutlinedTextFieldDefaults.colors() gives you access to several other colors as well.