Disable tooltipText in BottomNavigationView
Asked Answered
M

5

8

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?

enter image description here

Mimamsa answered 28/8, 2019 at 9:4 Comment(0)
S
9

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 BottomNavigationItemViews and calling TooltipCompat.setTooltipText(view, null)

Struble answered 4/10, 2019 at 16:50 Comment(3)
This works! I call the following code inside my Fragment.onViewCreated() bottomNavigationView.menu.forEach { TooltipCompat.setTooltipText(activity!!.findViewById(it.itemId), null) }Facia
Is there a XML solution?Maitland
@DIRTYDAVE you can add a binding adapter using data-bindingPressroom
Q
5

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
                }
            }
Quotation answered 17/9, 2020 at 13:45 Comment(0)
O
3

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)
  }
}
Ossify answered 9/1, 2020 at 6:7 Comment(1)
I don't like the idea of using reflection to do these things, but setting the long click listener part works for me.Pressroom
V
1

We could create an extension with this answser: https://mcmap.net/q/1262488/-disable-tooltiptext-in-bottomnavigationview

fun BottomNavigationView.disableTooltipText() {
    val menuIterator = menu.iterator()
    while(menuIterator.hasNext()) {
        val menu = menuIterator.next()
        findViewById<View>(menu.itemId)?.let { view ->
            TooltipCompat.setTooltipText(view, null)
        }
    }
}
Vidal answered 2/9, 2021 at 15:41 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Nationalize
H
0

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;
            }
        });

    }
Haggis answered 5/10, 2022 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.