解决方法:
给Toolbar加上app:contentInsetStart”="0dp"(左侧)或者“app:contentInsetEnd”="0dp"(右侧)
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp">
<!-- 自定义的布局-->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_dark"/>
</android.support.v7.widget.Toolbar>
注意:
我们这里用的是v7包下的Toolbar,所以要使用自定义的属性。如果你使用的是系统的Toolbar,则使用android:开头的属性才会生效。
或者通过自定义style去全局设置
此文通过学习博客: https://blog.csdn.net/afei__/article/details/51476096
做的笔记