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?
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.
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:
Or you can use the SupportLibrary with CardViews or something like that, they support elevation from API Level 7:
Hope this helps.