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

问题描述 投票:22回答:3

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

工具栏的xml视图是

<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);
}

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

android android-layout text android-support-library android-toolbar
3个回答
62
投票

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

ToolBar

完整代码:

<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" />

2
投票

在工具栏中添加app:contentInsetStartWithNavigation="0dp"


0
投票
Add this line app:contentInsetStartWithNavigation="0dp"        

<android.support.v7.widget.Toolbar
            android:id="@+id/share"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:navigationIcon="@drawable/action_back"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@{title}"
            android:background="4855b5"
            app:titleTextColor="ffffff"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
            app:titleTextAppearance="@style/Toolbar.TitleText"
            app:contentInsetStartWithNavigation="0dp" />
© www.soinside.com 2019 - 2024. All rights reserved.