Unknown android attribute: height

I am trying to follow a tutorial that would suggest how to add a floating button, and the tutorial says that add the android:elevation attribute to the xml buttons as follows:

 <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 doesn’t recognize this attribute ... I believe that it has something to do with my project target or sdk ... can anyone help me?

+6
source share
2 answers

To use android:elevation , like any other Android 5.0 API, you must compile it under Android 5.0 (API 21). This does not mean that you need to change the target SDK level or the minimum SDK level.

Note. Your XML file may still give a warning that android:elevation only works on Android 5.0 or later. This warning just tells you that previous versions of Android will not have a height shadow on a button with a floating action. However, this does not cause an error - previous versions of Android ignore XML attributes that they do not understand.

+13
source

The Elevation attribute is fairly new. It determines the climb to which it is applied. It is used for material design in the latest versions of Android.

Material Design

You can use it at API level 21, I think your target level is below that.

If you just want to achieve some shadow, you can use this:

Shadow Drawings for Views

Or you can use SupportLibrary with CardViews or something like that, they support a raise from API level 7:

[How-to] Use v21 Support Libs on older versions and Target L, while remaining compatible with feedback

Hope this helps.

+1
source

Source: https://habr.com/ru/post/979346/


All Articles