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

后端 未结 4 2058
南笙
南笙 2020-12-01 06:31

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

\"spac

相关标签:
4条回答
  • 2020-12-01 06:32

    Add app:contentInsetStartWithNavigation="0dp" in toolbar

    0 讨论(0)
  • 2020-12-01 06:43

    With the MaterialToolbar and the androidx.appcompat.widget.Toolbar you can use these attributes:

    • contentInsetStartWithNavigation: Minimum inset for content views within a bar when a navigation button is present, such as the Up button (default value=72dp).

    • contentInsetStart: Minimum inset for content views within a bar. Navigation buttons and menu views are excepted (default value = 16dp)

    • titleMarginStart: specifies extra space on the start side of the toolbar's title. If both this attribute and titleMargin are specified, then this attribute takes precedence. Margin values should be positive.

    Just use in your layout:

        <com.google.android.material.appbar.MaterialToolbar
            app:contentInsetStartWithNavigation="0dp"
            app:titleMarginStart="0dp"
            ..>
    

    Default:

    With app:contentInsetStartWithNavigation="0dp":

    With app:contentInsetStartWithNavigation="0dp" and app:titleMarginStart="0dp":

    You can also define a custom style:

    <style name="MyToolbar" parent="....">
        <item name="titleMarginStart">0dp</item>
        <item name="contentInsetStart">..dp</item>
        <item name="contentInsetStartWithNavigation">..dp</item>
    </style>
    
    0 讨论(0)
  • 2020-12-01 06:46

    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" />
    
    0 讨论(0)
  • 2020-12-01 06:58

    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" />
    
    0 讨论(0)
提交回复
热议问题