android - 如何缩小导航图标和工具栏标题之间​​的差距?

标签 android android-layout text android-support-library android-toolbar

我的问题是抽屉导航图标和工具栏标题之间​​的额外空间。示例图片如下:

spacing between nav-drawer icon and title

spacing between back icon and toolbar

工具栏的xml View 是

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextAppearance="@style/Toolbar.TitleText"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

我已尝试使用以下代码解决此问题,但未发生任何更改。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //toolbar.setTitleMarginStart(0);
    toolbar.setTitleMarginStart(-8);
}

有什么办法可以解决这个问题吗?

最佳答案

添加

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"

工具栏

完整代码:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextAppearance="@style/Toolbar.TitleText"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp" />

关于android - 如何缩小导航图标和工具栏标题之间​​的差距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40717684/

相关文章:

java - LWJGL 和 Slick2D 的文本错误

Javascript/Jquery 从字符串中获取 num 行

android - 一个 Activity 中有多个 ListView 。安卓?

javascript - 使用正则表达式从正文元素中选择单个文本字符

android - CircularReveal 动画在第一次尝试时不起作用

android - 推送通知 Symfony/Sly notification Pusher 上的 400 错误请求

android - 使用自定义转换器的两种方式数据绑定(bind)

java - "Error type 3 Error: Activity class {} does not exist",启动 Activity 时错误类型 3 Activity 类不存在

Textview和复选框的Android布局对齐

android-studio - 未知属性 android :scaleType