In mobile UI, buttons are often lacking text which makes them difficult to interpret. They can be ambiguous and clicking on them might seem intimidating to some users. Building intuitive UI is difficult and we should be taking advantage of more tools provided to us by Android, including the Tooltips.

“Some scenarios, such as those in productivity apps, require a descriptive method of communicating ideas and actions. You can use tooltips to display a descriptive message.” — Tooltips | Android Developers.

Tooltips

The Support Library provides an easy way to show a simple message when you long press on a view:

TooltipCompat.setTooltipText(archive, "Permanently archive item")

The tooltip looks like this:

Behind the scenes, it uses View.setTooltipText() on API 26+ and a back-ported version everywhere else.

A nice benefit is that hovering the mouse over this view will also trigger the tooltip (on Chrome OS too).

Accessibility

Since we are trying to help our users, we might as well kill two birds with one stone and add android:contentDescription to our button:

<ImageButton

android:id="@+id/archive"

android:contentDescription="@string/btn_archive_description"/>

Then, we can reuse it as the tooltip text:

TooltipCompat.setTooltipText(archive, archive.contentDescription)

Style

The framework doesn’t allow providing a custom style or view to use as the tooltip. But, since setTooltipText() accepts a CharSequence , we can pass a SpannableString to it to add some styling to the text:

StyleSpan + ForegroundColorSpan

Resources