Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Using Hints Instead of Tool Tips

In Chapter: Designing a successful Application
Author: Daniel Fowler ('GR8DAN')
Published? true
FormatLanguage: WikiFormat


Android devices can have small screens, there may not be room for help text, and tooltips are not part of the platform.


Android provides the hint attribute for Views.


Sometimes an input field needs clarification with regards to the value being entered. For example a stock ordering application asking for item quantities may need to state the minimum order size. In desktop programs, with large screens and the use of a mouse, extra messages can be displayed in the form of tooltips (a popup label near a field when the mouse moves over it). Alternatively, long descriptive labels may be used. With Android devices the screen may be small and no mouse is generally used. The alternative here is to use the android:hint attribute on a View. This causes a watermark containing the hint text to be displayed in the input field when it is empty; this disappears when the user starts typing in the field. The corresponding function for android:hint is setHint(int resourceId).

The color of the hint text can be set with android:textColorHint with setHintTextColor(int color) being the associated function.

Using these hints can also help with screen layouts when space is tight. It can allow labels to be removed to gain more space as the hints provide the necessary prompt for the user. A screen design can sometimes be improved by removing a label and using a hint.

The EditText definition in the above screen is shown here to see android:hint in use.

<EditText android:id="@+id/etQuantity"
    android:hint="Number of boxes of ten"

Hints can guide users filling in App fields, though like any feature over use is possible. Hints must not be used when it is obvious what is required, a field with a label of First Name would not need a hint such as Enter your first name here.


The source code for this project can be downloaded from http://tekeye.biz/download/hintexample.zip .