0

I have a problem in regards to toolbar. I can't figure out how to align searchview (which is a menu item in my case) in the toolbar. When the searchview is expanded, it pushes the icon it has on its right to the edge of the screen, while also removing any margin it had on its left. Important thing to note here is that I'm using the searchview as a menu item:

<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/search"
    android:icon="@drawable/ic_search"
    android:orderInCategory="1"
    android:title="Search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="ifRoom" />
<item
    android:id="@+id/filter"
    android:icon="@drawable/ic_filter"
    android:orderInCategory="2"
    android:title="Filter"
    android:visible="true"
    app:showAsAction="always" />

Let me visualize on images:

Exhibit A:

This is how I would like to have it, with the expanded searchview occupying the middle "title" part while maintaining its margins

This is how I would like to have it, with the expanded searchview occupying the middle "title" part while maintaining its margins

Exhibit B:

The reality

The reality

After looking and going through a ton of different threads and websites, I didn't find any solution that would help me. Do you have any ideas that I could try?

Austie
  • 67
  • 7
  • you can try add a menu item expandListenner to search menu item and when search expands set visibility GONE to the menu itens that you want to disable. – Bruno Ferreira Aug 07 '17 at 12:37
  • But I don't want to disable any buttons. I want to prevent the searchview from pushing them to the sides. As you can see, in the second image the right icon is in a different place than it was before the searchview was expanded. I want the searchview to expand but occupy only the available space without having any impact on the position of corner icons. – Austie Aug 07 '17 at 12:41
  • I'm not sure if [this link](https://stackoverflow.com/questions/27378981/how-to-use-searchview-in-toolbar-android) might help you – lalosoft Aug 07 '17 at 14:19

0 Answers0