Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Compose TextField: How to set exact 3 lines

I want to create TextField with exact 3 lines:

destination

I want to see 3 lines even without any text in this TextField, i.e. I need a direct equivalent of EditText.lines in classic xml layout.

My not working code is:

OutlinedTextField(
            value = currentText,
            onValueChange = { currentText = it },
            label = { Text ("Label") },
            maxLines = 3,
            modifier = Modifier.fillMaxWidth().wrapContentHeight().padding(16.dp),
            singleLine = false
        )

Could you help me?

like image 286
anil Avatar asked Feb 18 '26 15:02

anil


1 Answers

Starting from Starting from M2 1.4.0-alpha02 and M3 1.1.0-alpha02 you can use the minLines attribute in the TextField and OutlinedTextField:

OutlinedTextField(
    value = text,
    onValueChange = { text = it },
    label = { Text ("Label") },
    minLines = 3,
    maxLines = 3,
    modifier = Modifier.fillMaxWidth().wrapContentHeight().padding(16.dp)
)

enter image description here enter image description here

It can be used with M2 and M3.

like image 81
Gabriele Mariotti Avatar answered Feb 20 '26 06:02

Gabriele Mariotti



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!