10

Is it possible to set singleLine or maxLines on TextField?

I've checked a source and it's missing. Any ideas / workarounds?

Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61
Chesteer89
  • 101
  • 1
  • 3

3 Answers3

12

With 1.0.x you can use the parameter maxLines or singleLine:

TextField(
    //..
    maxLines = 1)

or

TextField(
    //..
    singleLine = true)
Gabriele Mariotti
  • 250,295
  • 77
  • 670
  • 690
3

Since Compose 1.0.0-alpha08, you can use singleLine parameter to make the text field a single horizontally scrollable line:

TextField(
    value = text,
    onValueChange = { },
    singleLine = true
)
Saurabh Thorat
  • 14,589
  • 3
  • 49
  • 62
0

I can't see any property which can do it directly. One work around could be:

TextField(
    value = yourText,
    onValueChange = { s: TextFieldValue ->
        if (s.text.count { it == '\n' } < 3) { // 3 lines (or two enters)
            yourText = s
        }
    }
)
nglauber
  • 9,971
  • 2
  • 44
  • 50