Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display ToolTip in android?

Tags:

android

I want to display the ToolTip(QuickAction View) when I am moving my cursor on the view. Can any one please give me the simple example for it? tooltip will only contains the text value.

like image 917
Thiru Avatar asked Aug 16 '12 09:08

Thiru


People also ask

How do I display tooltips?

Basic Tooltip HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .

How do I turn on tooltip?

How to Turn On Advanced Tooltips. The easiest way to turn on Advanced Tooltips in Minecraft is to press F3+H at the same time.

How does tooltip work on mobile?

Mobile tooltips are small in-app messages attached to a specific UI element or place on the screen. They're typically (but not exclusively) text-based, and are used to provide highly contextual guidance, highlight key features, or alert about new updates during app usage.

What is tooltip pop up?

A tooltip is pop-up text that is displayed when a user positions the cursor over a control in MicroStrategy Web.


2 Answers

Possibly using myView.setTooltipText(CharSequence) (from API-level 26) or TooltipCompat (prior to API-level 26) is an additonal option:

TooltipCompat.setTooltipText(myView, context.getString(R.string.myString)); 

Documentation says:

Helper class used to emulate the behavior of {@link View#setTooltipText(CharSequence)} prior to API level 26.

like image 79
Danny Avatar answered Oct 11 '22 21:10

Danny


Using AndroidX is the recommended way.

Android 4.0 (API 14) and higher

AndroidX support Library added support for tooltips (small popup windows with descriptive text) for views and menu items.

Use setTooltipText to set the tooltip text which will be displayed in a small popup next to the view.

See the following example:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); TooltipCompat.setTooltipText(fab, "Send an email"); 

The tooltip will be displayed:

  • On long click, unless it is handled otherwise (by OnLongClickListener or a context menu).
  • On hover, after a brief delay since the pointer has stopped moving

To add the Appcompat library into your project,

  1. Open the build.gradle file for your application.

  2. Add the support library to the dependencies section.

    dependencies {  compile "androidx.appcompat:appcompat:1.1.0" } 

Android 8.0 (API level 26) and higher

If your minimum supported version is Android 8.0 (API level 26) and higher, you can specify the tooltip text in a View by calling the setTooltipText() method. You can also set the tooltipText property using the corresponding XML.

To specify the tooltip text in your XML files, set the android:tooltipText attribute, as shown in the following example:

<android.support.design.widget.FloatingActionButton     android:id="@+id/fab"     android:tooltipText="Send an email" /> 

To specify the tooltip text in your code, use the setTooltipText(CharSequence) method, as shown in the following example:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setTooltipText("Send an email"); 
like image 28
Darish Avatar answered Oct 11 '22 23:10

Darish