我使用folloaing代码创建可折叠的工具栏布局
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appbar_layout"
android:orientation="vertical">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layoutdetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarCollapse"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="Fealty"
app:titleEnabled="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView8"
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="@android:color/darker_gray"
android:minHeight="190dp"
android:scaleType="fitXY"
android:src="@drawable/mlogin"
app:layout_collapseMode="parallax"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/favourite"
android:layout_gravity="bottom|end"
android:layout_marginEnd="20dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_toLeftOf="@+id/favourite"
android:layout_toStartOf="@+id/favourite"
android:src="@drawable/ic_launcher"
android:text="App Name"
android:textAppearance="?android:attr/textAppearanceMedium"
app:layout_anchor="@+id/app_bar_layout"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/favourite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/share"
android:layout_gravity="bottom|end"
android:layout_marginEnd="20dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/share"
android:layout_toStartOf="@+id/share"
android:src="@drawable/heart_out"
app:backgroundTint="#E91E63"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@+id/app_bar_layout"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView8"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|end"
android:layout_marginBottom="29dp"
android:layout_marginEnd="23dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_launcher"
app:backgroundTint="#E91E63"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@+id/app_bar_layout"
app:layout_anchorGravity="bottom|end"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="?attr/homeAsUpIndicator"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
问题是,当可折叠工具栏不处于可折叠状态时,后退箭头是可见的,但如果折叠后,后退箭头不可见。为什么这样?
答案 0 :(得分:2)
在CoordinatorLayout中删除此android:fitsSystemWindows="true"
。
在下面的setContentView
Toolbar toolbar = (Toolbar) findViewById(R.id.mainToolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);