Suyash
Suyash

Reputation: 2551

How to create consistent Material Design UIs if elevation attribute is not available on pre lollipop devices

Many of the Material Design UIs if not all are dependent on drop shadows. But sadly the elevation attribute is only present on Lollipop devices. So how to create a single consistent UI for your application if something as simple as drop shadows is not available on pre lollipop build versions?

There are of course some workarounds such as creating two versions of each layout, using nine patch drawables, using CardView, etc. But they all have certain problems:

  1. They require creating two versions of every layout, if you wan't to use the lollipop APIs as well for supported devices.
  2. Hard to implement for custom views with different shapes.
  3. Require separate drawables for every view, cluttering up the drawables folder.
  4. The shadows are considered a part of the view itself, so side by side placed views with the same elevation require use of negative margins.

So what is the solution to creating Material Design UIs that work on both Lollipop as well as pre Lollipop devices?

Upvotes: 2

Views: 360

Answers (2)

Fahim
Fahim

Reputation: 12378

Make use of android support libraries

http://developer.android.com/tools/support-library/features.html#v4-appcompat

Upvotes: -1

Zielony
Zielony

Reputation: 16537

It might not be the ideal solution, but for me using compatibility libraries for all Android versions works pretty well. I own a Galaxy S with Android Gingerbread, so it's really old and certainly doesn't support shadows and ripples. So I wrote a library backporting all things I needed. Rendering realtime shadows for arbitrary shapes is possible since Cupcake (or Froyo - I'm not sure). Ripples are very easy to implement. So it's like this:

  1. One version of each layout
  2. Supports any shape
  3. No additional drawables
  4. Shadows are drawn by layouts, not by shadow casters.

One of the problems is that there's no that new rendering thread, so for example the ripple animation lags when an Activity changes.

If you'd like to know more about my approach, check out my blog and github. https://androidreclib.wordpress.com/ https://github.com/ZieIony/Carbon

Upvotes: 1

Related Questions