android image button tooltip

user3536471 picture user3536471 · Apr 15, 2014 · Viewed 13k times · Source

I'm trying to build an app with image buttons that work like the action bar but i can't get them to show a tooltip on long press.

   <ImageButton
        android:id="@+id/editUrgent"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="48dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/editImportant"
        android:hint="@string/hint_urgent"
        android:contentDescription="@string/hint_urgent"
        android:text="@string/hint_urgent"
        android:src="@drawable/clock_light" />

android:contentDescription works for hovering(s-pen) but long press still does nothing.

Answer

AsterixR picture AsterixR · Sep 6, 2017

With api level 26 you can use the built-in TooltipText: Via XML:

android:toolTipText="yourText"

ViewCompatDocs

If your minSdk is below 26, use ToolTipCompat, for example:

TooltipCompat.setTooltipText(yourView, "your String");

Unfortunately, there's is no way to do this in your XML-File.