Android Tooltips – User Interface example in Kotlin

Android Tooltips is a hint to the user about a particular button or another view element. It shows the small pop message to a user on long-press the view or hovers their mouse on it. It’s useful because sometimes the only icon can adjust in screen and information (label) can be longer. This tutorial example, you will learn how to add tooltips on Android 8.0 (API level 26) and higher using kotlin.

A Tooltip may appear—a small “hover box” with information about the item being hovered over or long-press.

Android Tooltips - Us Interface example in Kotlin

In this tutorial, you will learn the following:

  1. Add the floating button in the layout
  2. Set Tooltip text in a floating button
  3. Default menu “hover box” text

Let’s Build a Simple Example of Android Tooltips :

Step 1. Create a new project “Build Your First Android App in Kotlin
Step 2. Add FloatingActionButton in resources layout “activity_main.xml
Step 3. Create a new menu and add following code

if you don’t have any menu resource file then create first “Android Resource directory” then create resource file “main_menu.xml”

for more information follow this tutorial – Android Toolbar example

Step 4. Open the “MainActivity.kt” and add the following code

In the code setting a tooltipText and menu in The Activity. For menu tooltipText will show the <itme> android:title = "Star mails"</> , Long press will popup the small text in the screen.

Step 5. Now Run the application, in an emulator or On you android device

Output screenshot Android Tooltips example :

Android Tooltips - User Interface example in Kotlin output

Download source code Android Tooltips in kotlin

Note: This example (Project) is developed in Android Studio 3.1.3. Tested on Android 9 ( Android-P), compile SDK version API 27: Android 8.0 (Oreo)



Coding in Kotlin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.