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
<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:contentInsetStart="0dp">
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v7.widget.Toolbar>
In my Activity
I add a back button like below
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if I set it to false it works okay. But I need to have a back button. Is there a way to solve it? Thank you.
I didn't use a menu layout
.
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">