How to Implement the Material-Design Elevation for Pre-Lollipop

How to implement the Material-design Elevation for Pre-lollipop

You can mimic the elevation on pre-Lollipop with a official method.

I achieve same effect using,

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

My tested output:

Sample Image

reference - https://stackoverflow.com/a/25683148/3879847

Thanks to user @Repo..

Update : If you want change color of this drawable try @Irfan answer below ↓

https://stackoverflow.com/a/40815944/3879847

Elevation on SlidingTabLayout in pre lollipop device

I found solutions through here, replace "android=elevation=" with a drawable xml file.

Add elevation/shadow on toolbar for pre-lollipop devices

For Android 5.0 and above : AppBarLayout automatically provides/gives shadow in the layout.
You can also increase the elevation of the AppBarLayout by app:elevation="4dp".

For Pre-Lollipop : You can use the following link: https://github.com/vipulasri/Toolbar-Elevation-Pre-Lollipop

Note: Toolbar also supports elevation to it, using android:elevation="4dp"


New Update: In Appcompat v24.0.0, you can not set elevation to AppBarLayout using setElevation() and app:elevation as these are deprecated.

You have to use stateListAnimator property to set elevation now.

Note: set duration to 1ms in StateListAnimator in order to avoid delay in Elevation Drawing.

AppBarLayout elevation change is delayed on appCompat v24.0.0

appbar_always_elevated.xml in animator-v21 folder under res directory.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<objectAnimator android:propertyName="elevation"
android:valueTo="8dp"
android:valueType="floatType"
android:duration="1"/>
</item>
</selector>

In AppbarLayout :

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:fitsSystemWindows="true"
android:stateListAnimator="@animator/appbar_always_elevated"
android:theme="@style/AppTheme.AppBarOverlay">

</android.support.design.widget.AppBarLayout>

android:elevation= doesn't work on devices pre-Lollipop with compile API21

Elevation requires the device to run Lollipop. See this answer on how to simulate elevation https://stackoverflow.com/a/26747592/680249

What is the best way to implement material design in pre-lollipop devices?

MaterialDesignLibrary by navasmdc seems to be forgoten with 150+ issues reported. It's also known for its conflicts with other libraries, lack of support and poor widget implementation.

Basically it depends on what would you like to achieve. Most of material features is too heavy to be used on older platforms. If you wish to have FloatingActionButton, Toolbar, RecyclerView and theming, you can use the Design Support Library and AppCompat from Google.

If you wish to have shadows, ripples and others, you should look for open-source libraries. Ray's lib is a very good example. Check out awesome-android and Android Arsenal. Both have a good list of material libraries.

I have my own library as well. It's called Carbon and it backports most of material features to Android 2.2+.

Elevation effect for ImageButton on Pre-Lollipop devices

You cannot use elevation pre 5.0, you need to provide an image with a "shadow" to make it appear like its elevated



Related Topics



Leave a reply



Submit