如何锁定OutlinedTextField中的LabelText?

huangapple go评论62阅读模式
英文:

How to lock LabelText in OutlinedTextField?

问题

我有一个用于OutlinedTextField字段的标题。它只在我点击字段并开始输入时出现。有没有办法修复我的标签,使其位置始终保持在顶部?

当用户开始输入时:
如何锁定OutlinedTextField中的LabelText?

当用户不输入任何内容时:
如何锁定OutlinedTextField中的LabelText?

我希望始终只有第一个版本

英文:

I have a header for an OutlinedTextField field. He show up. only when I click on the field and start typing. Is there a way to fix my label so that the position always stays on top?

When the user starts typing:
如何锁定OutlinedTextField中的LabelText?

When the user doesn't type anything:
如何锁定OutlinedTextField中的LabelText?

I want to always have only the first version

答案1

得分: 1

如果您需要将光标放在OutlinedTextField上,FocusRequester将会有所帮助。

val focusRequester = FocusRequester()

LaunchedEffect(Unit) {
    focusRequester.requestFocus()
}

然后将其应用于您的OutlinedTextField,如下所示:Modifier.focusRequester(focusRequester)

英文:

If you need cursor on the OutlinedTextField, FocusRequester will help you

val focusRequester = FocusRequester()

    LaunchedEffect(Unit) {
        focusRequester.requestFocus()
    }

and then apply it to your OutlinedTextField as Modifier
.focusRequester(focusRequester)

huangapple
  • 本文由 发表于 2023年3月8日 15:24:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定