I am implementing Fab. It is shown on devices API < 21
but it is not shown on devices with API >= 21
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/transparent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="@color/background_chart"
android:clickable="true">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/white_20"
android:dividerHeight="1dip"
android:footerDividersEnabled="false"
/>
</RelativeLayout>
<FrameLayout
android:id="@+id/toolbar_shadow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="@drawable/bottom_shadow"
android:foreground="@drawable/bottom_shadow" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_marginTop="@dimen/fab_margin_top"
android:layout_marginRight="@dimen/fab_margin_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_add"
app:borderWidth="0dp"
app:elevation="6dip"
app:pressedTranslationZ="12dp" />
</RelativeLayout>
How to show it for all api >=15?
Edit:
problem seems to be caused by 2 reasons.
1) in pre lollipop app:pressedTranslationZ="12dp"
moves FAB down (like margin top, where in lollipop it does not work as margin top any more, bat changes elevation of pressed state.
2) button is placed under layout with elevation 4 (toolbar), i tried to set different app:elevation
and android:elevation
for FAB, but it does not change anything.