在启用/禁用JetPack组成的TextField之后,如何管理TextField Focus?
我正在与Textfield合作,并且对重点遇到了一些问题。
禁用所有TextField,仅启用了第一个。当试图启用其他Textfield时,它失去了焦点,我们如何获得重点?
ScreenShot_20220602_121247
这是我的布局: -
在启用TextField时如何以编程方式移动焦点?
这是我用来启用和禁用TextField的代码段。
fun enabledDisabledTextField(
enteredValues: MutableList<String>,
index: Int,
isEnabled: Boolean): Boolean {
var enabled = isEnabled
val isFirstTime = enteredValues[0].isEmpty()
if (isFirstTime) {
if (enteredValues[index].isEmpty()) {
if (index == 0) {
enabled = true
}
if (index > 0) {
enabled = false
}
}
} else {
if (enteredValues[index].isEmpty()) {
enabled = true
}
if (enteredValues[index].isNotEmpty()) {
enabled = false
}
if (index == enteredValues.size - 1) {
enabled = true
}
}
return enabled
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在处理焦点管理时,我还没有尝试过此代码,但是有一个由
修改器
传播的功能,您可以在其中管理一些焦点属性,尽管我不确定这是否有效,并且如果您需要明确提供focusrequster
在box
的儿童focusmanager
上也提供了一些便利,并为其movefocus < /code>功能
猜测您的代码/逻辑,调用
focusrequester
在Textfield的修改器
上提供的,我不确定您是否必须创建list < /代码>
focusrequester
,每个代码将提供给您的每个textfield
I haven't tried to experiment this code yet when dealing with focus management, but there's a function exposed by
Modifier
where you can manage some focus properties, though I'm not quite sure if this would work and if you need to explicitly supply aFocusRequster
object on each of theBox
's childFocusManager
also provides some convenience with itsmoveFocus
functionGuessing your code/logic, call a
focusRequester
supplied on a textfield'sModifier
, again I'm not sure if you have to create alist
ofFocusRequester
and each of them will be supplied to each of yourTextField