[英]Change Cursor Position and force SingleLine of TextField in Jetpack Compose
[英]Jetpack Compose SingleLine Input Text
是否可以在 TextField 上設置 singleLine 或 maxLines?
我檢查了一個來源,它不見了。 任何想法/解決方法?
使用1.0.0-beta06
您可以使用參數maxLines
或singleLine
:
TextField(
//..
maxLines = 1)
或者
TextField(
//..
singleLine = true)
從Compose 1.0.0-alpha08 開始,您可以使用singleLine
參數使文本字段成為單個水平滾動行:
TextField(
value = text,
onValueChange = { },
singleLine = true
)
我看不到任何可以直接執行此操作的屬性。 一種解決方法可能是:
TextField(
value = yourText,
onValueChange = { s: TextFieldValue ->
if (s.text.count { it == '\n' } < 3) { // 3 lines (or two enters)
yourText = s
}
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.