I have an ImageButton, when I did some test for my app, I found that I could not show the tooltipText
in my Xiaomi Note 4 with Android N device. But it shows up perfectly fine in my Samsung S8 with Android O, any idea why this can happen and how to mitigate this? The minimum reproducible code is really simple, just create a basic android project in android studio and replace the default HelloWorld Textview to
<ImageButton
android:layout_width="36dp"
android:layout_height="36dp"
android:tooltipText="Show tooltip"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I think there must be some way I can make it work because the auto generated toolbar obviously has tooltip. So there must be something I'm missing to make it work in Xiaomi device.
Setting the tooltip textYou can specify the tooltip text in a View by calling the setTooltipText() method. You can set the tooltipText property using the corresponding XML attribute or API. FloatingActionButton fab = (FloatingActionButton) findViewById(R. id.
setTooltipText (CharSequence tooltipText)
is added in
added in API level 26. To use it in devices with API level prior 26, you can use TooltipCompat#setTooltipText(View view, CharSequence tooltipText)
from v7 support library.
To use it, add this in gradle
implementation "com.android.support:appcompat-v7:27.1.1"
`TooltipCompat.setTooltipText(view, "Tooltip text");`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With