How to reduce the gap between navigation icon and toolbar title?

我的梦境 提交于 2019-12-17 10:54:13

问题


My problem is the extra space between the nav-drawer icon and toolbar title. The sample images are below:

The xml view of the toolbar is

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

I have tried to solve this problem by using code below but no change occurred.

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

Is there any way to solve this problem ?


回答1:


Add

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

to the ToolBar.

Complete Code :

<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:


Add app:contentInsetStartWithNavigation="0dp" in toolbar




回答3:


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


来源:https://stackoverflow.com/questions/40717684/how-to-reduce-the-gap-between-navigation-icon-and-toolbar-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!