How to change Toolbar navigation icon and options menu margin

旧城冷巷雨未停 提交于 2019-12-17 21:56:27

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/26809133/how-to-change-toolbar-navigation-icon-and-options-menu-margin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!