I'm trying to follow a tutorial that suppose to show how to add a floating button and in the tutorial it says to add the attribute android:elevation
to the buttons xml like this:
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/editButton"
android:layout_gravity="center|right"
android:clickable="false"
android:background="@drawable/edit_grey"
android:layout_marginRight="1dp"
android:elevation="@dimen/elevation_low"/>
but it dosen't recognize that attribute...i believe it has something to do with my project target or sdk...can somebody help me?
To use android:elevation
, just as with any other Android 5.0 API, you must compile against Android 5.0 (API 21). This does not mean you have to change your target SDK level or minimum SDK level.
Note: your XML file may still give a warning that android:elevation
only works on Android 5.0 or higher. This warning just serves to tell you that previous versions of Android will not have an elevation shadow on the floating action button. However, that does not cause an error - previous versions of Android will ignore XML attributes they do not understand.
The Elevation attribute is pretty new. It defines the lift of the view it is applied to. It is used for the Material Design in the newest Android Versions.
Material Design
You can use it on API Level 21, I guess your targeted Level is lower than this.
If you just want to achieve some shadowing you can use this:
Shadow Drawables for Views
Or you can use the SupportLibrary with CardViews or something like that, they support elevation from API Level 7:
[How-to] Use the v21 Support Libs on Older Versions & Target L While Remaining Backwards-Compatible
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With