Skip to content

Most visited

Recently visited

navigation

Using Node Tree Debugging

Node tree debugging is a method of testing your app for accessibility.

About node tree debugging

Accessibility services use a separate representation of your app's UI to operate. As you debug, you might find it useful to view the hierarchy and attributes of UI elements in the same way that accessibility services view them. To accomplish this task, you can use node tree debugging. This tool provides information about how an AccessibilityService object, such as TalkBack, views UI elements within your app.

In node tree debugging, a window's content is presented as a tree of AccessibilityNodeInfo objects. Each node in the tree may have a set of AccessibilityAction objects associated with it. Each AccessibilityAction object, in turn, stores information about the interactions that it supports, such as focusable or clickable.

Note: The object hierarchy provided by the node tree debugging tool is simplified and may not map one-to-one with the corresponding hierarchy of View objects within an app's UI.

Turn on node tree debugging

To turn on node tree debugging, complete these steps:

  1. In Talkback Settings > Developer settings, select Enable node tree debugging.
  2. In Talkback Settings > Developer settings, set "Log output level" to Verbose.
  3. Configure a TalkBack gesture to print the node tree. This gesture is used to display the current view hierarchy to logcat.
    1. In Talkback Settings > Touch exploration, select Manage gestures.
    2. Select any gesture.
    3. Select Print node tree.
  4. Turn Talkback on.

Use node tree debugging

To use node tree debugging, complete these steps:

  1. Run the following command in a terminal window:

    $ adb logcat

    Note: Output from the logcat command can be noisy. To filter the logcat output, consider using the TreeDebug keyword.

  2. Open your app.
  3. Perform the gesture that you configured to print the node tree. The hierarchy tree is displayed in the terminal window.

Interpret node tree debugging output

The following two examples use a single LinearLayout with two child views, a CheckBox and a Switch. The node tree debugging tool recognizes that the LinearLayout element can be interpreted as a FrameLayout.

Note: The node tree debugging output in logcat displays physical pixel sizes and positions (px), not density-independent ones (dp).

Example: Screen without accessibility focus

<LinearLayout orientation="vertical">
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi, I'm a checkbox!"
        android:contentDescription="Testing a" />
    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toggle me!"
        android:contentDescription="Testing a" />
</LinearLayout>

When you perform the "Print node tree" gesture, if all of the following conditions are true:

...logcat then displays the following node tree:

V TreeDebug: (-2147453807)81.FrameLayout:(0, 0 - 1440, 2560):your-activity-name
V TreeDebug: (-2147450924)81.CheckBox:(56, 336 - 1384, 448):Hi, I'm a checkbox!:Testing a:FAC:( ):focusable:clickable
V TreeDebug: (-2147451885)81.Switch:(56, 448 - 1384, 543):Toggle me! OFF:Testing a:FAC:( ):focusable:clickable

This node tree shows the following information:

FrameLayout

CheckBox

Switch

Example: Screen with accessibility focus

When you perform the "Print node tree" gesture, if all of the following conditions are true:

...logcat then displays the following node tree:

V TreeDebug: (-2147453807)81.FrameLayout:(0, 0 - 1440, 2560):your-activity-name
V TreeDebug: (-2147450924)81.CheckBox:(56, 336 - 1384, 448):Hi, I'm a checkbox!:Testing a:FAC:(X):focusable:clickable
V TreeDebug: (-2147451885)81.Switch:(56, 448 - 1384, 543):Toggle me! ON:Testing a:FaC:(X):focusable:clickable:accessibilityFocused

This node tree shows the following information:

FrameLayout

CheckBox

Switch

To see a list of symbols used in node tree debugging to represent state and supported actions, see the TreeDebug class in the "talkback" GitHub project.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)