0

I am trying move focus from user textfield to password textfield with imeAction onNext and focusDirection.down, but the focus is cleared when I press the next button of the keyboard. UI image

I show the code here:

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)
                    }

                ),
    
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
agmcoder
  • 195
  • 1
  • 8
  • Please refer this answer https://stackoverflow.com/questions/66817856/what-is-the-simplest-way-to-set-the-focus-order-in-jetpack-compose – RaBaKa 78 Feb 25 '22 at 03:21

1 Answers1

0

Set singleLine , please try

OutlinedTextField(
...
singleLine = true,
)

simple example

@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
            )
        }
    }
}
Yshh
  • 654
  • 1
  • 10