2

In Android, when you onLongClick an overflow menu item icon, a tooltip of its title will appear.

I've tried setting the menu title to blank, but a blank tooltip will pop up.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/action_icon"
        android:title="Icon Title"
        android:icon="@drawable/ic_myicon"
        app:showAsAction="always"/>
</menu>

Notes:

• I'm using app namespace because Android Studio is telling me to use it due to having Theme.AppCompat.Light.NoActionBar as my theme. I've tried android namespace. Doesn't work either.

• My menu is created in a Fragment with hasOptionsMenu(true).

• My ActionBar is a Toolbar.

How can I remove this tooltip if it's possible? Thanks!

mco
  • 1,809
  • 15
  • 31

2 Answers2

0

the only way to do this is up is with android:showAsAction="withText" and set Title as =""

For onLongClickListener:

final MenuItem menuItem = menu.findItem(R.id.action_search);
            searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
            searchView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    return false;
                }
            });
JAAD
  • 12,349
  • 7
  • 36
  • 57
  • I'm sorry, but this does not work. `android:showAsAction="withText"` will force my menu item to be only shown as a text item. Together with `android:title=""` will result in a blank text menu item. I've tried `android:showAsAction="always|withText"`, but this does not work either. – mco Feb 06 '16 at 07:02
  • u can override menuitem onlongclick and then do nothing in it to not show tooltip – JAAD Feb 06 '16 at 07:06
  • `MenuItem` does not have a OnLongClickListener. Calling `MenuItem.getActionView()` is always null too... – mco Feb 06 '16 at 07:11
  • they have an onLongClick listener – JAAD Feb 06 '16 at 07:14
  • android:showAsAction="withText" is working for me i dont know why it isnt working for you – JAAD Feb 06 '16 at 07:16
  • hmm..Are you use AppCompat theme? – mco Feb 06 '16 at 07:18
  • I updated my question with my specific configuration for the menu. Also can you link me to the doc that shows MenuItem's OnLongClickListener? Appreciate it ty! – mco Feb 06 '16 at 07:36
  • final MenuItem menuItem = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(menuItem); searchView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return false; } }); – JAAD Feb 06 '16 at 07:40
  • Ok, I think I'm about to give up. `getActionView()` always returns `null.` – mco Feb 06 '16 at 07:50
0

Yes it is possible. In the java class remove the public boolean onCreateOptionsMenu(Menu menu) and the job will be done. If no remove this also from the java class public boolean onOptionsItemSelected(MenuItem item)

BlueSlimShady
  • 137
  • 11