Search code examples
javaandroidandroid-custom-view

How to create a info view in Android?


I had some textViews and image views in my app. On long pressing those views I need to show information regarding those views like in below picture. enter image description here In this picture on long pressing icon of overflow menu some info is displayed.

How can I create a custom info view like this. Any ideas please...


Solution

  • The answer of Mihir Shah is correct but according to documentation, it will only work from Android 8.0 (API level 26).

    So if your app minimum SDK is Android 8.0 (API level 26) you can use

    android:tooltipText="your message"
    

    in your XML code. Or use

    view.tooltipText = "message"
    

    in your java code.

    But if you target API level below 26 you need to use

    TooltipCompat.setTooltipText(view, "your message");
    

    also make sure your gradle have implementation 'androidx.appcompat:appcompat:1.3.1' this dependency.