Real Tech Hacks
Real Tech Hacks

Reputation: 367

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...

Upvotes: 1

Views: 149

Answers (2)

Mihir Shah
Mihir Shah

Reputation: 51

Just use tooltip

You can simply do this: Edit: For API 26+

view.tooltipText = "message"

Now, when you will longpress on your view it will automatically display the "message".

Also, you can use custom view instead of the default one.

Upvotes: 2

Venkat
Venkat

Reputation: 404

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.

Upvotes: 3

Related Questions