I think you have 2 options,
Set width to SearchView in styles
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
<item name="android:maxWidth">140dp</item>
</style>
Second option is get SeachView instance in onCreateOptionsMenu
and calculate width of your toolbar_title layout
set remaining width to search bar.
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setMaxWidth(calculatedWidth);
return super.onCreateOptionsMenu(menu);
}
But as per android standards, Search View has to extend completely in toolbar.
For this we have to use searchView.setMaxWidth(Integer.MAX_VALUE);
.
CLICK HERE to find out more related problems solutions.