Android更改材质高程阴影颜色 [英] Android change Material elevation shadow color

查看:926
本文介绍了Android更改材质高程阴影颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改xml提升属性产生的阴影颜色?
我希望通过代码动态更改阴影。

解决方案

我知道这个问题很老,可能是作者不再需要答案了。我会把它留在这里,以便其他人可以找到它。



Lollipop的提升系统不支持彩色阴影。



但是,如果你需要彩色阴影,可以使用Carbon来获得它们。它是Material Design的一种支持库,在最新版本中有一个改变阴影颜色的选项。 Behance上有很多漂亮的设计,上面有彩色阴影,我觉得尽管Android中缺少这样的功能,但还是很好。重要的是要注意,彩色阴影在所有 Android版本上模拟,也是5.0+。





代码:

 < carbon.widget.LinearLayout 
android:layout_width =match_parent
android:layout_height =wrap_content
android:orientation =horizo​​ntal>

< 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>


is it possible to change the shadow color produced by the xml elevation property? I want the shadow be dynamically changed by code.

解决方案

I know that this question is very old and probably the author doesn't need the answer anymore. I'll just leave it here so others can find it.

Lollipop's elevation system doesn't support colored shadows.

But, if you need colored shadows, it's possible to get them using Carbon. It's a kind-of support library for Material Design and in the most recent version there is an option to change shadow color. There's a ton of nice designs on Behance featuring colored shadows and I thought it would be nice to have them despite lack of such feature in Android. It's important to note that colored shadows are emulated on all Android versions, on 5.0+ too.

https://github.com/ZieIony/Carbon

The following image and code can be found in Carbon's samples.

Code:

<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>

这篇关于Android更改材质高程阴影颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆