TV devices provide a limited set of navigation controls for apps. Creating an effective navigation scheme for your TV app depends on understanding these limited controls and the limits of users' perception while operating your app. As you build your Android app for TVs, pay special attention to how the user actually navigates around your app when using remote control buttons instead of a touch screen.
This lesson explains the minimum requirements for creating effective TV app navigation scheme and how to apply those requirements to your app.
On a TV device, users navigate with controls on a remote control device, using either a directional pad (D-pad) or arrow keys. This type of control limits movement to up, down, left, and right. To build a great TV-optimized app, you must provide a navigation scheme where the user can quickly learn how to navigate your app using these limited controls.
The Android framework handles directional navigation between layout elements automatically, so you typically do not need to do anything extra for your app. However, you should thoroughly test navigation with a D-pad controller to discover any navigation problems. Follow these guidelines to test that your app's navigation system works well with a D-pad on a TV device:
The Android framework automatically applies a directional navigation scheme based on the relative position of focusable elements in your layouts. You should test the generated navigation scheme in your app using a D-pad controller. After testing, if you decide you want users to move through your layouts in a specific way, you can set up explicit directional navigation for your controls.
Note: You should only use these attributes to modify the navigation order if the default order that the system applies does not work well.
The following code sample shows how to define the next control to receive focus for a
TextView layout object:
<TextView android:id="@+id/Category1" android:nextFocusDown="@+id/Category2"\>
The following table lists all of the available navigation attributes for Android user interface widgets:
||Defines the next view to receive focus when the user navigates down.|
||Defines the next view to receive focus when the user navigates left.|
||Defines the next view to receive focus when the user navigates right.|
||Defines the next view to receive focus when the user navigates up.|
To use one of these explicit navigation attributes, set the value to the ID (
value) of another widget in the layout. You should set up the navigation order as a loop, so that
the last control directs focus back to the first one.
The success of an app's navigation scheme on TV devices is depends on how easy it is for a user to determine what user interface element is in focus on screen. If you do not provide clear indications of focused items (and therefore what item a user can take action on), they can quickly become frustrated and exit your app. For the same reason, it is important to always have an item in focus that a user can take action on immediately after your app starts, or any time it is idle.
Your app layout and implementation should use color, size, animation, or a combination of these attributes to help users easily determine what actions they can take next. Use a uniform scheme for indicating focus across your application.
Android provides Drawable State List Resources to implement highlights for focused and selected controls. The following code example demonstrates how to enable visual behavior for a button to indicate that a user has navigated to the control and then selected it:
<!-- res/drawable/button.xml --> <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:state_hovered="true" android:drawable="@drawable/button_focused" /> <!-- hovered --> <item android:drawable="@drawable/button_normal" /> <!-- default --> </selector>
The following layout XML sample code applies the previous state list drawable to a
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/button" />
Make sure to provide sufficient padding within the focusable and selectable controls so that the highlights around them are clearly visible.
For more recommendations on designing effective selection and focus for your TV app, see Patterns for TV.