# Toolbar 自定义布局去除左右两边间距

Toolbar 自定义布局去除左右两边间距

在工作中遇到了toolbar 嵌套布局发现左右边距不一样大 ,所以发现了并加以修改

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/holo_blue_bright">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_red_dark" />

    </android.support.v7.widget.Toolbar>

经过查阅

app:contentInsetStart=”0dp”

只不过是间距变窄了一些。经过测试,发现还要设置 toolbar 的 paddingLeft 和 paddingRight 值为 0,当然,直接设置 padding 为 0 也是可以的。加上之后终于没有间距了:

如果在代码里设置了显示返回箭头,即

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

则需要给布局添加属性设置:

app:contentInsetStartWithNavigation=”0dp”

可以看到,返回箭头占的位置变窄了。
最后,完整布局是这样的:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/holo_blue_bright"
        android:padding="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_red_dark" />

    </android.support.v7.widget.Toolbar>

clone:https://blog.csdn.net/musiclife123/article/details/80417825?utm_source=blogxgwz1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值