问题描述
我已经搜索了几天如何制作这些颜色阴影和高程效果,但在任何地方都不清楚。 最简单的方法是什么?
解决方法
Starting API 28 (Pie) View#setOutlineAmbientShadowColor(int color) 和 View#setOutlineSpotShadowColor(int color) 在 View 类中可用。
如果您在视图上使用高程,则可以使用这两种方法来更改阴影的颜色。
您可以使用 CardView 制作阴影。
,最简单的方法之一:
卡片视图
卡片视图以及支持高度。
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="20dp" />
注意:在卡片视图的背景中,您只能使用简单的颜色。如果您想要更多选项,您可以将您的图片或 drawable 放在子背景中。
像这样:
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="20dp" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/flag_peru" <= use this options
>
.
.
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>