【问题标题】:Reduce padding between navigation icon and logo on my toolbar减少工具栏上导航图标和徽标之间的填充
【发布时间】:2015-10-21 15:41:05
【问题描述】:

有谁知道如何减少工具栏上导航图标和徽标之间的填充。出于某种原因,它们之间的空间似乎比我的徽标和标题之间的空间大。

我已经尝试添加样式并使用 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>

Image (Space indicated by red lines should be smaller)

【问题讨论】:

标签: android icons navigation-drawer padding toolbar


【解决方案1】:

如果您只对在我的工具栏上减少导航图标和徽标之间的填充感兴趣,请使用 Toolbar.setContentInsetStartWithNavigation(0)

contentInsetStart 不同,只有在 是一个导航图标。在没有导航图标的情况下,您将 仍然有 16dp 的起始插图。

【讨论】:

  • @Henry 感谢您的澄清。
【解决方案2】:

只需在您的工具栏 xml 中添加 app:contentInsetStart="0dp"

添加app:contentInsetStart="0dp"前输出为:

添加app:contentInsetStart="0dp"后输出为:

希望它的帮助。 完成

【讨论】:

  • 我在我的Toolbar 中使用了相同的app:contentInsetStart="0dp,但它不起作用。请帮助我
  • @RavindraKushwaha 你解决了吗?我也有同样的问题,将 contentInsetStart 设置为 0dp 没有帮助。
  • @Rahul 请参考此链接,它可以为您提供帮助stackoverflow.com/a/45628064/3946958
  • @Ravindra Kushwaha,在我的例子中,目标布局被放置在一个仍然有自己的填充的容器中,所以设置没有效果。