문제

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