Reputation: 283
My Toolbar
Google Play Toolbar
How can I remove unnecessary padding?
My toolbar is inside the fragment My code in fragment:
public void setUpToolbar(Toolbar toolbar, String title, @DrawableRes int resId) {
toolbar.setTitle(title);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
ab.setHomeAsUpIndicator(resId);
ab.setDisplayHomeAsUpEnabled(true);
}
My toolbar in xml:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
Upvotes: 26
Views: 11819
Reputation: 17841
Had this problem recently, and even after setting all the insets
to 0dp
there was still a gap between the NavigationIcon and the Title. Apparently this is the Margin of the TitleView, and to remove this we have to set app:titleMarginStart="0dp"
.
So on the whole, had to do the below to remove the entire gap.
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:titleMarginStart="0dp"
Upvotes: 4
Reputation: 4108
Use this inside your toolbar xml tag
app:contentInsetStartWithNavigation="0dp"
Upvotes: 45
Reputation: 701
Try to add app:contentInsetLeft:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay" />
Upvotes: 3
Reputation: 4013
Just add in your toolbar
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
It should work
Upvotes: 19
Reputation: 6392
Try this in your code:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
actionBar.setCustomView(customView);
Toolbar parent =(Toolbar) customView.getParent();
parent.setContentInsetsAbsolute(0,0);
Upvotes: 3