【问题标题】:What is Elevation Overlay In Android [closed]什么是Android中的高程叠加[关闭]
【发布时间】:2024-04-10 14:50:01
【问题描述】:

我多次遇到海拔叠加。即使我阅读了一些定义,我似乎也没有找到它的确切含义。你能帮我解决这个问题吗?它是什么?它是如何使用的?

这里是link

【问题讨论】:

  • “我多次遇到高程叠加”——您能否编辑您的问题并提供指向使用该术语的地点的链接?你指的是material.io/develop/android/theming/dark吗?
  • 感谢您对 CommonsWare 的评论。我编辑了它
  • 谢谢尤努斯的链接,但是看不到很多用处;(。想知道怎么用(在什么情况下)

标签: android material-design material-components-android android-dark-theme


【解决方案1】:

您可以在doc 中找到:

深色主题中,立面叠加层是半透明的白色 (colorOnSurface) 概念上放置在 表面颜色。

由图书馆管理
只是一个MaterialCardViewapp:cardElevation="4dp"app:cardElevation="8dp" 的示例。

灯光模式:

黑暗模式:

叠加层基于应用主题中定义的colorOnSurface
您可以在应用主题中更改此颜色添加:

<item name="elevationOverlayColor">@color/...</item>

您也可以在应用主题中禁用此行为:

<item name="elevationOverlayEnabled">false</item>

材质组件库中的许多组件都支持深色主题中的高程叠加,但您也可以使用 MaterialShapeDrawable 在自定义视图中应用它。

例如,您可以使用LinearLayout

LinearLayout linearLayout1= findViewById(R.id....);
MaterialShapeDrawable shapeDrawableLL1 = 
MaterialShapeDrawable.createWithElevationOverlay(this, 4.0f );
ViewCompat.setBackground(linearLayout1,shapeDrawableLL1);

LinearLayout linearLayout2= findViewById(R.id....);
MaterialShapeDrawable shapeDrawableLL2 = 
MaterialShapeDrawable.createWithElevationOverlay(this, 16.0f );
ViewCompat.setBackground(linearLayout2,shapeDrawableLL2);

【讨论】:

  • 非常感谢您的回答。我现在明白了很多
最近更新 更多