设置返回按钮在ToolBar上,边距出现在按钮顶部,按钮下移Android 4.4

Setting the Back Button On the ToolBar, the margin appears at the top of the button, and the button moves down in Android 4.4

设置工具栏的后退按钮在工具栏上,边距出现在按钮的顶部,按钮下移 Android 4.4,在5.X, 6.X, 7.X上面显示正常。

代码如下:

layout.xml:

<android.support.v7.widget.Toolbar
                android:id="@+id/my_collection_tool"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:contentInsetStart="0dp"
                app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
                app:layout_scrollFlags="scroll|enterAlways"
                app:titleTextColor="@color/white" />

UI 效果:

这是我的 layout.xml,正在 Android 4.4:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

请尝试使用。也许问题出在您的应用主题或某些其他工具栏设置中。

而不是在 xml 文件中添加 navigationIcon。之后写下一行。

setContentView(R.layout.....)
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true); 

并在单击后退箭头时执行操作

 if (id == R.id.option1) {
     // it is id of any other menu available on the toolbar
} else {
    //write your code which should be execute on the click of back arrow

    onBackPressed(); // for navigating back
    finish();
}

如果 getActionbar 不支持使用 getSupportActionbar instead.It 将在工具栏中添加后退导航箭头