How to reduce the gap between navigation icon and toolbar title?
Add
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
to the ToolBar
.
Complete Code :
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" />
With the MaterialToolbar
and the androidx.appcompat.widget.Toolbar
you can use these attributes:
contentInsetStartWithNavigation
: Minimum inset for content views within a bar when a navigation button is present, such as the Up button (default value=72dp
).contentInsetStart
: Minimum inset for content views within a bar. Navigation buttons and menu views are excepted (default value =16dp
)-
titleMarginStart
: specifies extra space on the start side of the toolbar's title. If both this attribute andtitleMargin
are specified, then this attribute takes precedence. Margin values should be positive.
Just use in your layout:
<com.google.android.material.appbar.MaterialToolbar
app:contentInsetStartWithNavigation="0dp"
app:titleMarginStart="0dp"
..>
Default:
With app:contentInsetStartWithNavigation="0dp"
:
With app:contentInsetStartWithNavigation="0dp"
and app:titleMarginStart="0dp"
:
You can also define a custom style:
<style name="MyToolbar" parent="....">
<item name="titleMarginStart">0dp</item>
<item name="contentInsetStart">..dp</item>
<item name="contentInsetStartWithNavigation">..dp</item>
</style>
Add app:contentInsetStartWithNavigation="0dp"
in toolbar
Add this line app:contentInsetStartWithNavigation="0dp"
<android.support.v7.widget.Toolbar
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/action_back"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@{title}"
android:background="4855b5"
app:titleTextColor="ffffff"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:contentInsetStartWithNavigation="0dp" />