Reputation: 1232
Im using
implementation 'com.google.android.material:material:1.1.0-alpha09'
this is my menu
<item
android:id="@+id/llHome"
android:icon="@drawable/selector_menu_home"
android:title="@string/navigation.bottom.home"
app:tooltipText="@null" />
but as much as I write long click or disable it, the tooltip with the name of the menu continues to appear. Any idea how to disable the tooltip?
Upvotes: 8
Views: 4676
Reputation: 159
Actually
bottomNavigationView.menu.forEach {
TooltipCompat.setTooltipText(activity!!.findViewById(it.itemId), null)
}
is not working after pressing the bottom button.
Here is my solution:
fun BottomNavigationView.disableTooltipText() {
try {
val menuViewField = this.javaClass.getDeclaredField("menuView")
menuViewField.isAccessible = true
val menuView = menuViewField.get(this) as BottomNavigationMenuView
menuView.forEach {
it.setOnLongClickListener {
true
}
}
} catch (e: Exception) {
Log.w(e)
}
}
Upvotes: 3
Reputation: 7
Nothing was working for me until I combined the above answers and did this:
for (int i = 0; i < bottomNavigationView.getMenu().size(); i++) {
bottomNavigationView.findViewById(bottomNavigationView.getMenu().getItem(i).getItemId()).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return true;
}
});
}
Upvotes: 0
Reputation: 36
We could create an extension with this answser: https://stackoverflow.com/a/58240404/9871226
fun BottomNavigationView.disableTooltipText() {
val menuIterator = menu.iterator()
while(menuIterator.hasNext()) {
val menu = menuIterator.next()
findViewById<View>(menu.itemId)?.let { view ->
TooltipCompat.setTooltipText(view, null)
}
}
}
Upvotes: 1
Reputation: 4027
This not works for me, bottomNavigationView.menu.forEach { TooltipCompat.setTooltipText(activity!!.findViewById(it.itemId), null) }
is not working so below answer worked for me
bottomNavigationView.menu.forEach {
val view = bottomNavigationView.findViewById<View>(it.itemId)
view.setOnLongClickListener {
true
}
}
Upvotes: 5
Reputation: 8006
It will either show the tooltip text or the tab title. You might be able to clear out the text by iterating over all the BottomNavigationItemView
s and calling TooltipCompat.setTooltipText(view, null)
Upvotes: 9