1

I'm trying to create a custom TextField using Android Jetpack compose, see below

                  TextFieldDefaults.OutlinedTextFieldDecorationBox(
                    contentPadding = PaddingValues(vertical = 10.dp),
                    value = searchText,
                    innerTextField = innerTextField,
                    enabled = enabled,
                    singleLine = singleLine,
                    visualTransformation = VisualTransformation.None,
                    interactionSource = interactionSource,
                    colors = textFieldColors,
                    leadingIcon = {
                        Icon(
                            modifier = Modifier.size(leadingIconSize),
                            painter = painterResource(id = R.drawable.ic_search),
                            contentDescription = ""
                        )
                    },
                    placeholder = {
                        Text("what is doin ")
                    }
                )

The height of the text field should be 36dp due to design requirements, however the text field has its own height about 56dp.

I could not find any information how to customize that value so I used the parameter contentPadding to achieve the goal.

However, it seems too ugly for me. Is there any other way to achieve to implement this?

Thanks in advance.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Oğuzhan Aslan
  • 166
  • 2
  • 10
  • Does this answer your question? [Jetpack Compose Decrease height of TextField](https://stackoverflow.com/questions/67681416/jetpack-compose-decrease-height-of-textfield). Also, you can try to override `defaultMinSize`. – Sky Nov 03 '22 at 09:01
  • Yes, it does, thanks. I missed it while searching through :/ – Oğuzhan Aslan Nov 03 '22 at 10:39

1 Answers1

2

Apply the height modifier to the BasicTextField.
Something like:

    BasicTextField(
        value = text,
        onValueChange = { text = it },
        modifier = Modifier
            .height(36.dp),
        singleLine = singleLine,
        interactionSource = interactionSource
    ) { innerTextField ->
        TextFieldDefaults.OutlinedTextFieldDecorationBox(
            value = text,
            innerTextField = innerTextField,
            enabled = enabled,
            singleLine = singleLine,
            visualTransformation = VisualTransformation.None,
            interactionSource = interactionSource,
            contentPadding = TextFieldDefaults.textFieldWithoutLabelPadding(
                top = 0.dp,
                bottom = 0.dp 
            )
        )
    }

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841