I am trying to adjust the start padding of the label in my TextSearchBar
composable.
I understand that one option is to use a BasicTextField
composable but i want to avoid this and use contentPadding
parameter via decorationBox
added in androidx.compose.material:material:1.2.0-alpha04
(mentioned by jeran in below post).
I am having difficulties in adding decorationBox (not too familiar on how lambda parameter function works). Please help how i can implement decorationBox to adjust the start padding of the label text?
remove default padding on jetpack compose textfield.
@Composable
fun TextSearchBar(
modifier: Modifier = Modifier,
value: String,
label: String,
onDoneActionClick: () -> Unit = {},
onClearClick: () -> Unit = {},
onFocusChanged: (FocusState) -> Unit = {},
onValueChanged: (String) -> Unit,
) {
TextField(
value = value,
onValueChange = { query ->
onValueChanged(query)
},
modifier = modifier
.padding(horizontal = 4.dp, vertical = 0.dp)
.fillMaxWidth()
.onFocusChanged { onFocusChanged(it) },
textStyle = MaterialTheme.typography.subtitle1,
label = { Text(text = label) },
trailingIcon = {
IconButton(onClick = { onClearClick() }) {
Icon(imageVector = Icons.Filled.Clear, contentDescription = "Clear")
}
},
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
),
keyboardActions = KeyboardActions(onDone = { onDoneActionClick() }),
singleLine = true,
colors = TextFieldDefaults.textFieldColors(textColor = Color.Gray,
backgroundColor = Color.LightGray,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent
),
//decorationBox = {???}
)
}