How Can I Remove The Left Space Between Back Button And Searchview
I keep having a big white space in the left of my Toolbar between the back button and SearchView. My xml file looks like this
Solution 1:
By default, Toolbar
have 16dp inset after backbutton. So, include app:contentInsetStartWithNavigation="0dp"
in Toolbar
, it will remove that whitespace.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp">
Solution 2:
Add these lines in your Toolbar
android:contentInsetLeft="0dp"android:contentInsetStart="0dp"app:contentInsetLeft="0dp"app:contentInsetStart="0dp"android:contentInsetRight="0dp"android:contentInsetEnd="0dp"app:contentInsetRight="0dp"app:contentInsetEnd="0dp"
Solution 3:
Add this property in the SearchView
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="-16dp"
android:paddingStart="-16dp"/>
and check it. Hope this will help you.
Solution 4:
Use MaxWidth option to do it programmatically in onCreateOptionsMenu() method
@overridepublicbooleanonCreateOptionsMenu(Menu menu) {
MenuInflaterinflater= getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
SearchViewsearchView= (SearchView)menu.findItem(R.id.menu_search).getActionView();
searchView.setMaxWidth(Integer.MAX_VALUE);
if using Kotlin use:
searchView.maxWidth = Integer.MAX_VALUE
Post a Comment for "How Can I Remove The Left Space Between Back Button And Searchview"