The support library doc states that the version 22.2 supports FloatingActionButton on Pre-Lollipop devices.
I have implemented a demo app to show a FAB on KitKat.
The FAB is shown but I still can't set the elevation neither in the xml nor in the code.
In the xml I get the warning and I need to use tools:ignore="NewApi"
. If I call setElevation
programmatically I get an exception because the method does not exist.
I have added this to my layout
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_button"
style="@style/FAB"
android:src="@drawable/ic_add_white_24dp"
android:contentDescription="@string/add_ringtone" />
where the style is defined like this:
<resources
xmlns:tools="http://schemas.android.com/tools">
<style name="FAB" tools:ignore="NewApi">
<item name="android:layout_width">@dimen/fab_width</item>
<item name="android:layout_height">@dimen/fab_height</item>
<item name="android:background">@drawable/fab_background</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_marginBottom">@dimen/fab_margin</item>
<item name="android:layout_marginRight">@dimen/fab_margin</item>
<item name="android:elevation" >@dimen/fab_elevation</item>
<item name="android:stateListAnimator">@anim/rise</item>
</style>
</resources>
What should I do to set the elevation on KitKat with the new support library?