Rulogarcillan
Rulogarcillan

Reputation: 1232

Disable tooltipText in BottomNavigationView

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

Upvotes: 8

Views: 4676

Answers (5)

Swifty
Swifty

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

Chris_Gr
Chris_Gr

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

Moro
Moro

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

Navin Kumar
Navin Kumar

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

Cameron Ketcham
Cameron Ketcham

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

Upvotes: 9

Related Questions