减少工具栏上导航图标和Logo之间的填充距离。

4

有没有人知道如何减少工具栏上导航图标和标志之间的填充。由于某些原因,在它们之间的空间似乎比我的标志和标题之间的空间要大得多。

我已经尝试添加样式并使用contentInset,但它们都似乎不起作用。

我的布局

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/background_grey"
android:style="@style/ToolbarTheme"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:logo="@drawable/ic_launcher">

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

我的风格

<style name="ToolbarTheme" parent="Theme.AppCompat">
    <item name="android:minWidth">0dip</item>
    <item name="android:paddingLeft">0dip</item>
    <item name="android:paddingRight">0dip</item>
</style>

图片(红线所示的空间应更小)


你能否发布一个工具栏的截图,其中包含导航图标和徽标,在这个截图中你遇到了问题。 - Karthik
@Karthik 我已经添加了一张图片。 - Jason Lie
可能是如何减小导航图标和工具栏标题之间的间隔?的重复问题。 - computingfreak
2个回答

16
如果您只对“减少工具栏上导航图标和徽标之间的填充”感兴趣,请使用 Toolbar.setContentInsetStartWithNavigation(0) contentInsetStart 不同,仅在存在导航图标时才会修改插入。 在缺少导航图标时,您仍将拥有16dp起始插入。

@Henry 感谢澄清。 - pRaNaY

0
只需在您的工具栏 XML 中添加 app: contentInsetStart ="0dp"
在添加app: contentInsetStart ="0dp"之前,输出为:

enter image description here

在添加了 app:contentInsetStart="0dp" 之后,输出结果如下:

enter image description here 希望对你有所帮助。 完成


1
我在我的工具栏中使用了相同的app:contentInsetStart="0dp",但它没有起作用。请帮助我解决这个问题。 - Ravindra Kushwaha
@RavindraKushwaha,你解决了吗?我也遇到了同样的问题,将contentInsetStart设置为0dp也没有帮助。 - Rahul
@Rahul 请参考此链接,它可能对你有帮助 https://stackoverflow.com/a/45628064/3946958 - Ravindra Kushwaha
@Ravindra Kushwaha,在我的情况下,目标布局放置在一个仍然具有自己填充的容器中,因此设置没有效果。 - kirkadev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接