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-->
Customization (see the 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! ;)