Android toolbar 左边距问题

toolbar会有左边距,我被这个东西坑了,怎么也没法把自己的控件放到我想要的位置。后来才发现有左边距这个坑。。。
说来也很好解决,在这里稍作记录。
图片来自网络

解决办法:
1:设置单个bar的左边距:
在toolbar控件中加入以下属性即可

 app:contentInsetStart="0dp"
.support.v7.widget.Toolbar
        android:id="@+id/main_toolbar"
        android:fitsSystemWindows="true"
        android:background="#00000000"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:contentInsetStart="0dp">

2:设置整个app bar的左边距:
在style文件中加入下面那个自定义的toolbarStyle即可。
注意:这里要有系统的actionbar,没有的话即设置主题为NoActionBar的话无效果。



        

        

你可能感兴趣的:(Android toolbar 左边距问题)