Keyboard order - Jetpack Compose

In Jetpack Compose, to change the default focus traversal order for navigation, you can use the focusProperties modifier to specify the item that should receive focus when navigating up, down, or in any other direction.

You can use the following focusProperties:

  • next: specifies which element should receive focus when navigating to the next.
  • previous: specifies which element should receive focus when navigating to the previous.
  • up: specifies which element should receive focus when navigating up.
  • down: specifies which element should receive focus when navigating down.
  • left: specifies which element should receive focus when navigating to the left.
  • right: specifies which element should receive focus when navigating to the right.
  • start: specifies which element should receive focus when navigating to the left in LTR mode and right in RTL mode.
  • end: specifies which element should receive focus when navigating to the right in LTR mode and left in RTL mode.
// Create set of reference for each Composable
val (first, second, third, fourth) = remember { FocusRequester.createRefs() }
Button(
    onClick = { },
    modifier = Modifier
        .focusRequester(fourth)
        .focusProperties {
            down = third
            right = second
        }
) {
    // Button content...
}