1

In Android compose is there anyway to center text within a TextField?

    TextField(
    value = text,
    onValueChange = setText,
    maxLines = 2,
    modifier = modifier
        .clip(RoundedCornerShape(10.dp))
        .background(Color(0xffe2ebf0))
        .border(BorderStroke(5.dp, color = MaterialTheme.colors.secondary), shape = RoundedCornerShape(1.dp)),
    textStyle = MaterialTheme.typography.h3,
    keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
    keyboardActions = KeyboardActions(onDone = { submit() })

)

Cannot post images yet... So here is a link!

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Lucas
  • 323
  • 1
  • 8

1 Answers1

1

You can use textAlign = TextAlign.Center in the TextStyle.

Something like:

TextField(
    //...your code
    textStyle = MaterialTheme.typography.h3.copy(textAlign = TextAlign.Center),
)

enter image description here

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