有什么方法可以在API<中创建材质样式的阴影. 21(5.0棒棒糖)? [英] Is there any way to do a Material-style shadow in API < 21 (5.0 Lollipop)?
问题描述
材料设计十分强调在纸页"的隐喻上.为了制造这些,阴影是必不可少的.由于材料设计是一种哲学,而不是不是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.+'
这篇关于有什么方法可以在API<中创建材质样式的阴影. 21(5.0棒棒糖)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!