How to change Toolbar navigation icon and options menu margin

20,699

I went through the Toolbar source code to find a solution and it turned out to be pretty simple.

Toolbar uses two styles to style the toolbar and the navigation icon. Just had to override those styles with my own.

<style name="myToolbarNavigationButtonStyle" parent="@style/Widget.AppCompat.Toolbar.Button.Navigation">
    <item name="android:minWidth">0dp</item>
    <item name="android:padding">12dp</item>
    <item name="android:scaleType">centerInside</item>
</style>

<style name="myToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
    <item name="android:paddingRight">10dp</item>
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="toolbarStyle">@style/myToolbarStyle</item>
    <item name="toolbarNavigationButtonStyle">@style/myToolbarNavigationButtonStyle</item>
</style>
Share:
20,699

Related videos on Youtube

timemanx
Author by

timemanx

Updated on July 09, 2022

Comments

  • timemanx
    timemanx almost 2 years

    Is there any way to change the left margin of the Navigation icon and the right margin of the Action items in Toolbar?

  • Eric Schlenz
    Eric Schlenz over 8 years
    Does anyone have a github repository they can point to that leverages this solution? I've tried numerous things at this point, including this solution. None of them seem to work for me. A full working project that could be shared would be very helpful.
  • timemanx
    timemanx over 8 years
    @EricSchlenz Ok. I'll create one.
  • Sagar Panwala
    Sagar Panwala over 8 years
    @ShubhadeepChaudhuri : This is not working for me. Do you have any idea? Please help me.
  • Mullazman
    Mullazman about 8 years
    This get's rid of my actionbar buttons and makes the single navigation button the whole width of my toolbar, any ideas?