我在我的styles.xml
中使用了<item name="android:windowTranslucentNavigation">true</item>
。
由于有透明的导航栏,我为浮动操作按钮添加了边距。
我的问题是,我的Snackbar在透明的导航栏下面。我通过给Snackbar添加填充来解决这个问题,但现在我的Snackbar和浮动操作按钮之间的空间太大了。我尝试为我的浮动操作按钮创建自定义行为,但是导航栏的自定义边距和Snackbar的填充会导致当Snackbar被关闭或显示时高度出错。
这是我的浮动操作按钮,它位于android.support.design.widget.CoordinatorLayout
中,并具有属性android:fitsSystemWindows="true"
。
<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right|end"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
app:borderWidth="0dp"
app:elevation="12dp"
app:layout_behavior="...ScrollAwareFABBehavior"
app:rippleColor="@color/md_indigo_700" />
我还没有找到一种方法来对齐FloatingActionButton
和SnackBar
以使它们显示在NavigationBar
之上,同时不破坏behavior
。
我的CoordinatorLayout
位于一个片段中。这是活动布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
碎片布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/fragment_toolbar" />
<com.pnikosis.materialishprogress.ProgressWheel
android:id="@+id/progress_wheel"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:visibility="gone"
wheel:matProg_barColor="#5588FF"
wheel:matProg_progressIndeterminate="true" />
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/navigation_bar_bottom_padding"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right|end"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
app:borderWidth="0dp"
app:elevation="12dp"
app:layout_behavior="...ScrollAwareFABBehavior"
app:rippleColor="@color/md_indigo_700" />
</android.support.design.widget.CoordinatorLayout>