android – How to remove padding from title in toolbar?-ThrowExceptions

Exception or error:

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" />
How to solve:

Use this inside your toolbar xml tag

app:contentInsetStartWithNavigation="0dp"

###

Just add in your toolbar

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

It should work

###

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);

###

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" />

Leave a Reply

Your email address will not be published. Required fields are marked *