0

我正在尝试使用 imeAction onNext 和 focusDirection.down 将焦点从用户文本字段移动到密码文本字段,但是当我按下键盘的下一个按钮时焦点被清除。 用户界面图片

我在这里显示代码:

val focusManager = LocalFocusManager.current
//we start to implement login screen UI-->
    LazyColumn(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        item {
            
        item {
            OutlinedTextField(

                value = emailValue.value,
                keyboardOptions = KeyboardOptions(
                    imeAction = ImeAction.Next,
                    keyboardType = KeyboardType.Password
                ),
                keyboardActions = KeyboardActions(
                    onNext ={
                        focusManager.moveFocus(FocusDirection.Down)
                    }

                ),
    
4

1 回答 1

0

设置 singleLine ,请尝试

OutlinedTextField(
...
singleLine = true,
)

简单的例子

@Composable
fun Test() {
    val focusManager = LocalFocusManager.current
    var text1 by remember {
        mutableStateOf("")
    }
    LazyColumn() {
        items(2){
            OutlinedTextField(value = text1, onValueChange = {
                text1 = it
            },
                keyboardOptions = KeyboardOptions(
                    imeAction = ImeAction.Next,
                    keyboardType = KeyboardType.Text
                ),
                keyboardActions = KeyboardActions(
                    onNext ={
                        focusManager.moveFocus(FocusDirection.Down)
                    }
                ),
                singleLine = true
            )
        }
    }
}
于 2022-02-25T01:05:44.750 回答