首页 > 解决方案 > Android 海拔不适用于深色背景色

问题描述

<LinearLayout
        android:id="@+id/headerContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/dark_green"
        android:elevation="32dp"
        android:outlineProvider="background"/>

我尝试使用上面的代码添加下拉阴影,但如果背景颜色较暗,我看不到阴影。但如果颜色是白色的,它工作得很好。

请不要建议<layer-list>或绘制。我需要使用轮廓和高度。

标签: android

解决方案


您可以将视图包裹在 cardview 中以获得阴影效果。

如果要更改卡片背景颜色,请使用:

app:cardBackgroundColor="@somecolor"

像这样:

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@color/white">

</android.support.v7.widget.CardView>

推荐阅读