سؤال

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