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...

有帮助吗?

解决方案 2

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

<item name="android:icon">@android:color/transparent</item>

其他提示

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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top