[ Web Proxy ]
URL:
Viewing: https://developer.android.com/develop/ui/compose/touch-input/focus [Back]  [Original]

Focus in Compose  |  Jetpack Compose  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Focus in Compose Stay organized with collections Save and categorize content based on your preferences.

When a user interacts with your app, they often do so by touching elements on their screen. However, this is not the only form of interaction. Other forms of interaction could include the following:

In these cases, it is important to track which component is active at any given point in time, which is what we call focus. Elements on the screen should be focused in a logical order. Jetpack Compose has a default way of handling focus that is correct in most cases. However, in some cases, you might need to modify this default behavior.

The following pages describe how to use focus in your app:

Default focus traversal order

Before we dive into the default behavior of the focus search, it's important to understand the concept of level in the hierarchy: generally speaking, we can say that two Composables are at the same level when they are siblings, meaning that they have the same parents. For instance, elements inside a Column are at the same level. Getting up a level means going from a child to its Composable parent, or, keeping the same example, going back from an item to a Column that contains it. Going down a level is the other way around, from the Column parent to the contained items. This concept can be applied to every Composable that can contain other Composables.

Note: For information about manually controlling focus order, see Control traversal order.

UI navigation can happen in multiple ways, some of which most users will already know:

Take as an example the screenshot below, where you have four buttons, one below the other, and you want to cycle through them all in order of appearance. Jetpack Compose delivers this behavior out of the box: the toolkit lets you cycle through each composable in vertical order from top to bottom using the tab key, or move focus by pressing the up or down arrow.

Screenshot of a list of buttons placed vertically one below the other in a small form factor. [Screenshot of a list of buttons placed vertically one below the other in a small form factor.] Figure 1. List of buttons displayed in a small form factor

When you switch to a different kind of layout, things change a bit. If your layout has more than one column, like the layout below, Jetpack Compose lets you navigate through them without having to add any code. If you press the tab key, Jetpack Compose automatically highlights the items in order of declaration, from First to Fourth. Using arrow keys on your keyboard makes the selection follow the desired direction in 2D space.

Column {
    Row {
        TextButton({ }) { Text("First field") }
        TextButton({ }) { Text("Second field") }
    }
    Row {
        TextButton({ }) { Text("Third field") }
        TextButton({ }) { Text("Fourth field") }
    }
}

The Composables are declared in two Rows, and the focus elements are declared in order, from first to fourth. When you press the tab key, this produces the following focus order:

Screenshot of a list of buttons placed in two columns side by side in a bigger form factor. [Screenshot of a list of buttons placed in two columns side by side in a bigger form factor.] Figure 2. List of buttons placed in two columns side by side in a bigger form factor

In the snippet below, you declare the items in Columns rather than in Rows:

Row {
    Column {
        TextButton({ }) { Text("First field") }
        TextButton({ }) { Text("Second field") }
    }
    Column {
        TextButton({ }) { Text("Third field") }
        TextButton({ }) { Text("Fourth field") }
    }
}

This layout traverses the items vertically, from top to bottom, from the start of the screen towards the end:

Screenshot of a list of buttons placed in two columns side by side in a bigger form factor. [Screenshot of a list of buttons placed in two columns side by side in a bigger form factor.] Figure 3. List of buttons placed in two columns side by side in a bigger form factor

The previous two samples, while differing in one-directional navigation, provide the same experience when it comes to two-dimensional navigation. This is usually because the items on the screen have the same geographic placement in both examples. Navigating right from the first Column moves the focus to the second, and navigating down from the first Row moves the focus to the one below it.

Note: Focus properties are a special case, in which the parents always win in case of collisions or duplicates. This is something to keep in mind when working with focus.
Change focus traversal order

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-07-21 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-07-21 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page