7

I have a problem, where I need a BasicTextField to customize the TextField as I want.

Here I have tried to do a custom, but there is a problem with the cursor in the BasicTextField, it doesn't center align, what I need is center alignment

Screen Created.

Expectation: expectation

i code like this

BasicTextField(
    value = value,
    onValueChange = onValueChange,
    decorationBox = { innerTextField ->
        Column(
            modifier = Modifier
                .fillMaxWidth(),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            innerTextField()

            Space(height = 8.dp)

            Divider()
        }
    }
)

1 Answer 1

6

You can apply textAlign = TextAlign.Center to the textStyle attribute in the BasicTextField.

Something like:

BasicTextField(
        value = text,
        onValueChange = { text = it },
        textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
        decorationBox = { innerTextField ->
            Column(
                modifier = Modifier
                    .fillMaxWidth(),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                innerTextField()
                Spacer(modifier = Modifier.height(8.dp))
                Divider()
            }
        }
    )
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.