是否可以更改 xml 高程属性产生的阴影颜色? 我希望通过代码动态更改阴影。
最佳答案
我知道这个问题很老了,可能作者不再需要答案了。我就把它留在这里,以便其他人可以找到它。
Lollipop 的海拔系统不支持彩色阴影。
但是,如果您需要彩色阴影,可以使用 Carbon 来获得它们。它是一种对 Material Design 的支持库,在最新版本中,有一个更改阴影颜色的选项。 Behance 上有很多不错的设计,带有彩色阴影,我认为尽管 Android 中没有这样的功能,但拥有它们会很好。请务必注意,在 所有 Android 版本(包括 5.0+)上也会模拟彩色阴影。
https://github.com/ZieIony/Carbon
以下图片和代码可以在 Carbon 的示例中找到。
代码:
<carbon.widget.LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<carbon.widget.Button
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_margin="@dimen/carbon_padding"
android:background="#ffffff"
app:carbon_cornerRadius="2dp"
app:carbon_elevation="8dp"
app:carbon_elevationShadowColor="@color/carbon_red_700"/>
</carbon.widget.LinearLayout>
“卡片 View ”:
<carbon.widget.LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<carbon.widget.LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_margin="@dimen/carbon_margin"
android:background="#ffffff"
app:carbon_cornerRadius="2dp"
app:carbon_elevation="8dp"
app:carbon_elevationShadowColor="@color/carbon_red_700">
<carbon.widget.ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/test_image"/>
<carbon.widget.TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test text"/>
</carbon.widget.LinearLayout>
</carbon.widget.LinearLayout>
关于java - Android更改 Material 高程阴影颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29187313/