Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change label direction in the OutlinedTextField

I have an OutlinedTextField in jetpack compose and I want to change the label direction to the right of OutlinedTextField for the Persian language (By default is on the left).

enter image description here

like image 784
Saeed Noshadi Avatar asked Oct 26 '25 12:10

Saeed Noshadi


1 Answers

Use CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl).

Sample code,

@Composable
fun RtlLabelInOutlineTextField() {
    val (digit1, setDigit1) = remember {
        mutableStateOf("")
    }
    CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
        OutlinedTextField(
            value = digit1,
            onValueChange = {
                setDigit1(it)
            },
            label = {
                Text("Label")
            },
            keyboardOptions = KeyboardOptions(
                keyboardType = KeyboardType.NumberPassword,
                imeAction = ImeAction.Next,
            ),
            modifier = Modifier.fillMaxWidth().padding(16.dp),
        )
    }
}

Screenshots

Screenshots Screenshots Screenshots

like image 125
Abhimanyu Avatar answered Oct 29 '25 03:10

Abhimanyu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!