How to implement the elevation property in api 19 and lower?

3

I'm doing a project in android studio and I want to use the property elevation for LinearLayout but as the app will also be directed to lower versions of the api 20

    
asked by FuriosoJack 24.12.2016 в 18:31
source

1 answer

2

To do this you have to simulate the elevation:

You can define background in your view this Shape :

android:background="@drawable/my_background"

This would be the my_background.xml file that is created inside the /drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
    <solid android:color="#BDBDBD"/>
    <corners android:radius="5dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
    <solid android:color="#ffffff"/>
    <corners android:radius="5dp"/>
</shape>
</item>
</layer-list>

Another known method is to add as background the drawable dialog_holo_light_frame of the SDK:

android:background="@android:drawable/dialog_holo_light_frame"

With both options you can get something similar to the property elevation :

The third option is to create a Drawable 9 patch whose image contains the elevation shadow and which you would use as the background of your view:

link

    
answered by 24.12.2016 / 22:04
source