How to remove padding from title in toolbar?
Asked Answered
E

5

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" />
Ezzo answered 24/7, 2016 at 16:16 Comment(2)
https://mcmap.net/q/497075/-remove-margin-in-android-toolbar-iconBeagle
app:contentInsetStartWithNavigation="0dp"Beagle
F
44

Use this inside your toolbar xml tag

app:contentInsetStartWithNavigation="0dp"
Fleck answered 9/5, 2017 at 15:15 Comment(0)
E
19

Just add in your toolbar

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

It should work

Erratic answered 24/7, 2016 at 20:39 Comment(0)
G
4

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"
Gangster answered 29/5, 2021 at 3:52 Comment(0)
E
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);
Edita answered 24/7, 2016 at 17:1 Comment(0)
C
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" />
Cattail answered 24/7, 2016 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.