質問

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