Make Searchview width to full width

Viewed 110

I want the length of searchview to occupy full width of action bar when clicked but instead it shows the others items as well. This is xml file of the view

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_settings"
        android:title="Settings"
        app:showAsAction="never"/>
    <item
        android:id="@+id/about"
        android:title="About"
        app:showAsAction="never"
        />
    <item
        android:id="@+id/edit"
        android:icon="@drawable/ic_baseline_sort_24"
        app:showAsAction="always"
        android:title="Edit"/>
   
    <item android:id="@+id/search"
        android:title="search_title"
        android:icon="@drawable/ic_search"
        app:showAsAction="always|collapseActionView"
        app:actionViewClass="androidx.appcompat.widget.SearchView" />

</menu>

In the java file I am trying the following

 androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) 
                                      item.getActionView();
                       searchView.setMaxWidth(Integer.MAX_VALUE);

It is working as regular search bar with other items shown as well along the bar.

0 Answers
Related