Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose align input text in TextField

I would like to achieve similar behaviour with TextField from Jetpack Compose like from old school XML layout:

<EditText
    android:id="@+id/some_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right" /> <!-- or end -->

When I try this approach:

TextField(value = "", onValueChange = {

}, textAlign = TextAlign.End) 

It simply just doesn't work because textAlign property doesn't exists in TextField. Then how to do input text alignment like TextAlign.Center, TextAlign.End, TextAlign.Justify and so on for TextField?

like image 701
Arsenius Avatar asked Jan 25 '23 07:01

Arsenius


1 Answers

You can do it through textStyle.

TextField(
    value = "",
    onValueChange = {

    },
    textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.End)
)

LocalTextStyle.current is the default value for TextField, you can replace it by your own.

like image 153
Philip Dukhov Avatar answered Feb 01 '23 10:02

Philip Dukhov