Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

android - How remove extra padding above Jetpack Compose OutlinedTextField?

I'm trying to put OutlinedTextField into the Column after Box element like this

@Composable
fun Header() {
    Column {
        Box(
            modifier = Modifier
                .border(1.dp, Color.Cyan)
        ) {
            Text("Header")
        }

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .border(1.dp, Color.Cyan),
            value = "",
            onValueChange = {},
            placeholder = {
                Text("Enter header")
            }
        )
    }
}

Borders added to see exact size of elements. It looks like this
enter image description here with extra 8dp padding above, but when I use TextField instead of OutlinedTextField there are no extra space

@Composable
fun Header() {
    Column {
        Box(
            modifier = Modifier
                .border(1.dp, Color.Cyan)
        ) {
            Text("Header")
        }

        TextField(
            modifier = Modifier
                .fillMaxWidth()
                .border(1.dp, Color.Cyan),
            value = "",
            onValueChange = {},
            placeholder = {
                Text("Enter header")
            }
        )
    }
}

enter image description here I need to know why it is happening and how to solve it

Version of library is "androidx.compose.material:material:1.0.0-alpha10"

question from:https://stackoverflow.com/questions/65842430/how-remove-extra-padding-above-jetpack-compose-outlinedtextfield

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Padding above OutlinedTextField is there because the label moves to the top when in focus, which requires space.

Material Specs

If you don't want this feature, you can create your own outlined text field composable by modifying BasicTextField.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...