Kamil
Kamil

Reputation: 13931

Round rectangle corners and shadows in Android 4.x?

I want to create something close to Material Theme in app that is supposed to work with Android 4.x and 5.x.

I have tried to use Material theme, but I need api 21 for that. My current minimum api is 15 and I want to keep that.

Do I have to create shadows as PNG images or there is easier way?

I want to keep application compatybile with Android 4.x and I have no time to maintain two versions (for Android 4.x and 5.x).

Upvotes: 1

Views: 394

Answers (1)

Zielony
Zielony

Reputation: 16537

I wouldn't call it an easy way, but you can mimic real animated shadows on any device above Android Cupcake. Here's how it works:

  • draw your view to an off-screen bitmap with LightingColorFilter set to 0,0
  • blur the black shape (the off-screen bitmap) using the ScriptIntrinsicBlur class and elevation value as radius
  • draw the bitmap beneath the view

It requires adding custom elevation attributes, custom views capable of rendering shadows, and using render script and the compatibility library (for older devices).

If you'd like to see that solution in action, check my library:

https://github.com/ZieIony/Carbon

Upvotes: 1

Related Questions