Java Android更改材质立面阴影颜色

Java Android更改材质立面阴影颜色,java,android,xml,shadow,material-design,Java,Android,Xml,Shadow,Material Design,是否可以更改xml提升属性生成的阴影颜色? 我想通过代码动态地改变阴影。我知道这个问题很老了,可能作者不再需要答案了。我就把它放在这儿,这样别人就能找到了 棒棒糖的仰角系统不支持彩色阴影 但是,如果你需要彩色阴影,可以使用碳元素来实现。它是一种材质设计支持库,在最新版本中,有一个选项可以更改阴影颜色。Behance上有很多很好的设计,都有彩色阴影,我想,尽管Android中没有这样的功能,但拥有它们还是不错的。需要注意的是,在5.0+上,所有Android版本都模拟了彩色阴影 下图和代码可以在

是否可以更改xml提升属性生成的阴影颜色?
我想通过代码动态地改变阴影。

我知道这个问题很老了,可能作者不再需要答案了。我就把它放在这儿,这样别人就能找到了

棒棒糖的仰角系统不支持彩色阴影

但是,如果你需要彩色阴影,可以使用碳元素来实现。它是一种材质设计支持库,在最新版本中,有一个选项可以更改阴影颜色。Behance上有很多很好的设计,都有彩色阴影,我想,尽管Android中没有这样的功能,但拥有它们还是不错的。需要注意的是,在5.0+上,所有Android版本都模拟了彩色阴影

下图和代码可以在Carbon的样品中找到

代码:


“CardView”:


启动API 28(饼图)并在View类中提供


如果在视图上使用“立面”,则可以使用这两种方法来更改阴影的颜色。

可以使用。检查我的。

否,框架提供的阴影颜色无法更改。由于我对CardView上的阴影颜色感兴趣,我发现了一些东西,但不知道如何使用它:
https://github.com/gabrielemariotti/cardslib/blob/master/doc/SHADOW.md
我也发现了这个:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.1_r1/frameworks/support/v7/cardview/res/values/colors.xml
这是:
https://developer.android.com/training/material/shadows-clipping.html
看起来无法更改阴影的颜色。您是否可以详细说明如何使用碳来创建彩色阴影?我目前无法使它工作。提前谢谢。我添加了一个片段。您可以在存储库中找到完整的示例。它位于示例应用程序的“功能/阴影”下。如果您遇到任何问题,请随时打开一个问题并在那里讨论。非常感谢。但问题是,我想在CardView或类似的系统上使用它,这样我就可以在其中包含ChildView。因此,在我的例子中,按钮不起作用。除此之外,还可以在主题xml中将它们设置为@color/yourAmbientShadow@color/yourSpotShadow
<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>
<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>