1

I'm using the SearchView widget of the ActionBar (standard version, not ABS), and I am trying to hide the application icon that is displayed on the left side of the expanded SearchView. It's already hidden in the application, and it's only visible when the SearchView is open, which is not what I want.

I found that the SearchView has a setOnCloseListener, but nothing to handle the open event...

Gaëtan
  • 11,912
  • 7
  • 35
  • 45
  • Check: http://stackoverflow.com/questions/18806877/remove-icon-title-for-actionbar-with-expanded-searchview – Paresh Mayani Apr 30 '14 at 08:42
  • I already use this `getActionBar().setDisplayShowHomeEnabled(false)` and setting the LayoutParams of the SearchView did not fix it either. – Gaëtan Apr 30 '14 at 08:59

2 Answers2

4

You can try something like this, I did not test it but it is worth a try ("menu_search" being the MenuItem displaying the SearchView:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity, menu);

    MenuItem searchMI = (MenuItem) menu.findItem(R.id.menu_search);
    searchMI.setOnActionExpandListener(new OnActionExpandListener(){
        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            //nothing
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            getActionBar().setDisplayShowHomeEnabled(false);
            return true;
        }
    });
    return true;
}
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • I didn't know this listener, but it seems that it has no effect either ... The fact that it is available in Android 4.0+ is also an issue for me, as I support Android 3.0+. – Gaëtan Apr 30 '14 at 14:42
  • I got an error when I used the setOnActionExpandListener, but it worked for me with `MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {...}` – Eve Jan 03 '17 at 12:06
2

To solve this, I just had to add this in my style for the ActionBar:

<item name="android:icon">@android:color/transparent</item>
Gaëtan
  • 11,912
  • 7
  • 35
  • 45