Areyana
Areyana

Reputation: 385

How to hide tooltips on menuItem's in BottomNavigationView?

How to hide tooltips on menuItem's in BottomNavigationView ? Now i can't get how to control this behaviour. I'm already tried something like this:

    for (item in vBottomNavigation.children) {
        TooltipCompat.setTooltipText(item, null)
    }

or

 TooltipCompat.setTooltipText(vBottomNavigation, null)

or finally

   vBottomNavigation.setOnLongClickListener {
        true
    }

But nothing worked, also i tried set tooltipText in menu resources to @null or empty string, but anyway i see tooltips on long press on bottom menu items.

I want to control visibility of tooltips on the bottomnavigation view. Any ideas ?

Upvotes: 1

Views: 2879

Answers (2)

shoheikawano
shoheikawano

Reputation: 1175

If you do not want to show this tooltip on long click, you can override BottomNavigationItemView's long click behavior by setting OnLongClickListener to the menu items, like the code below(I tried this solution with BottomNavigationView from material components with the following version: com.google.android.material:material:1.2.0-alpha04) :

bottomNavigation.menu.forEach {
  val view = bottomNavigation.findViewById<View>(it.itemId)
  view.setOnLongClickListener {
    // your logic here
    true
  }
}

Note that this tooltip behavior is set to each BottomNavigationItemView that BottomNavigationView inflates on its constructor, so the tooltip behavior is not set to BottomNavigationView itself.

Upvotes: 4

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364025

Currently there isn't a method to show/hide the tooltip.
You can set the tooltipText with:

  • TooltipCompat.setTooltipText(item,"...")
  • bottomNavigationView.getMenu().getItem(i).setTooltipText("...")

However in the BottomNavigationView there is this code:

CharSequence tooltipText = !TextUtils.isEmpty(itemData.getTooltipText())
    ? itemData.getTooltipText()
    : itemData.getTitle();
TooltipCompat.setTooltipText(this, tooltipText);

If your tooltip is empty or "" the title will be displayed.

Upvotes: 0

Related Questions