有什么方法可以在API<中创建材质样式的阴影. 21(5.0棒棒糖)? [英] Is there any way to do a Material-style shadow in API < 21 (5.0 Lollipop)?

查看:86
本文介绍了有什么方法可以在API<中创建材质样式的阴影. 21(5.0棒棒糖)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

材料设计十分强调在纸页"的隐喻上.为了制造这些,阴影是必不可少的.由于材料设计是一种哲学,而不是不是API (尽管它内置在L中),所以应该在任何地方(Windows窗体,HTML/CSS等)完成. 如何在Android API 14至20中做到这一点?

Material design makes a huge emphasis on the metaphor of "sheets of paper". To make these, shadows are essential. Since Material design is a philosophy and not an API (despite it being built into L), this should be done anywhere (Windows Forms, HTML/CSS, etc.). How do I do this in Android API 14 to 20?

请注意,预制的PNG对于圆形和其他非正方形形状实际上并不实用.

Note that premade PNGs won't really be that practical for circular and other non-square shapes.

推荐答案

如果您不担心Lollipop的向后兼容性,则可以直接在XML中设置海拔高度属性

If you're not worried about backwards compatibility past Lollipop, you can set the elevation Attribute directly in the XML

    android:elevation="10dp"

否则,您必须使用support.v4.ViewCompat库在Java中进行设置.

Otherwise you have to set it in Java using the support.v4.ViewCompat library.

    ViewCompat.setElevation(myView, 10);

并将其添加到您的build.gradle

and add this to your build.gradle

    compile 'com.android.support:support-v4:21.+'

http://developer.android.com/reference/android/support/v4/view/ViewCompat.html#setElevation(android.view.View,%20float)

这篇关于有什么方法可以在API<中创建材质样式的阴影. 21(5.0棒棒糖)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆