设置后退按钮在工具栏上,边距显示在按钮的顶部,按钮在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" />
答案 0 :(得分:0)
这是我的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" />
请尝试使用它。也许问题出在您的应用主题或其他一些工具栏设置中。
答案 1 :(得分:0)
而不是在xml文件中添加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();
}
并点击后退箭头
执行操作prev
如果getActionbar不支持使用getSupportActionbar。它将在工具栏中添加后退导航箭头