HintedImageButton

Additional

Language
Kotlin
Version
1.0.6 (May 25, 2019)
Created
Sep 15, 2018
Updated
May 29, 2019
Owner
Hendra Wijaya Djiono (hendrawd)
Contributor
Hendra Wijaya Djiono (hendrawd)
1
Activity
Badge
Generate
Download
Source code
APK file

Blurb

HintedImageButton

ImageButton that shows hint using toast when long clicked

   

How to use?

  • Add jitpack url in your root build.gradle
allprojects {
   repositories {
      maven { url 'https://jitpack.io' }
   }
}
  • Add the dependency
dependencies {
    implementation 'com.github.hendrawd:HintedImageButton:x.x.x'
}

Where x.x.x is the latest release version. Check the latest release version here

  • Use
<hendrawd.library.customview.HintedImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_xxx"
    android:contentDescription="Put your hint here!"
    android:background="@drawable/optional_selector"
    />
<!-- use android:background="@null" if you want to remove the background-->

or directly within anko layout

frameLayout { 
    hintedImageButton { 
       // set properties
    }
}

Customization (see example project for more clarity)

  • Set duration
<hendrawd.library.customview.HintedImageButton
    app:hintDuration="durationLong"
    />
<!-- "durationShort" or "durationLong", default="durationShort" -->
hintedImageButton.hintDuration = HintedImageButton.DURATION_LONG // or HintedImageButton.DURATION_SHORT
  • Set custom layout
hintedImageButton.setCustomLayout(yourCustomLayout, yourTextView)

New Attribute in Android Oreo

Starting from Android Oreo, if your requirement is just to show simple tooltip to any View, you can use android:tooltipText attribute directly without this library in order to display a simple Toast-like tooltip when user long-presses or mouse hover on a View

<View
    android:id="@+id/yourView"
    android:tooltipText="@string/view_tooltip"/>

Although it has limitation with minimum API 26, you can still use it through the Support Library's TooltipCompat helper class

TooltipCompat.setTooltipText(yourView, getString(R.string.view_tooltip))

Have fun! ;)