Search code examples
androidmenuandroid-appcompatsearchview

SearchView in AppCompat distorts icon


I am stuck in a very weird situation, my SearchView is working perfectly. I just need to use OnActionExpandListener and for that purpose, I have to set app:showAsAction="ifRoom|collapseActionView" in my SearchView item in menu layout.

What it does is, it distorts my SearchView icon. If I use app:showAsAction="always", OnActionExpandListener stops working but icon is shown perfectly.

Any kind of help is this regard will be highly appreciated, thanks.

Edit: See the comments on the answer.


Solution

  • I agree, they have failed doing this nicely. Anyway, I use this instead in order to detect when SearchView is being expanded/closed.

    searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
                // Opened
            }
    
            @Override
            public void onViewDetachedFromWindow(View v) {
                // Closed
            }
        });