25

My Toolbar

My toolbar

Google Play Toolbar

GooglePlay 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" />
guipivoto
  • 18,327
  • 9
  • 60
  • 75
gape
  • 273
  • 1
  • 3
  • 4

5 Answers5

44

Use this inside your toolbar xml tag

app:contentInsetStartWithNavigation="0dp"
Abdul Rizwan
  • 3,904
  • 32
  • 31
19

Just add in your toolbar

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

It should work

Rick
  • 3,943
  • 6
  • 33
  • 45
3

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);
Nir Duan
  • 6,164
  • 4
  • 24
  • 38
3

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" />
Alexey Rogovoy
  • 691
  • 6
  • 13
3

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"
Henry
  • 17,490
  • 7
  • 63
  • 98