How to add a tooltip to a button in Android

How to add a tooltip to a Button in Android:

Tooltip is a helper text that appears near a view when user long press on it. This is available for API 26 and higher, or Android 8.0 and higher.

In this post, I will show you how to add tooltip to a Button.

Adding a tooltip:

We can add a tooltip directly in the xml file or dynamically. To add it in the xml file, android:tooltipText is used. We can provide one string for this. Also, we can change it using tooltipText property.

For example,

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android=""
    android:tooltipText="Dummy Button"
    android:text="Click Me"/>

Here, I added a tooltip text to the Button.

It will show a tooltip if you long press on the button.

Android tooltip example

You might also like: