java - Android更改 Material 高程阴影颜色

标签 java android xml shadow material-design

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

最佳答案

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

Lollipop 的海拔系统不支持彩色阴影。

但是,如果您需要彩色阴影,可以使用 Carbon 来获得它们。它是一种对 Material Design 的支持库,在最新版本中,有一个更改阴影颜色的选项。 Behance 上有很多不错的设计,带有彩色阴影,我认为尽管 Android 中没有这样的功能,但拥有它们会很好。请务必注意,在 所有 Android 版本(包括 5.0+)上也会模拟彩色阴影。

https://github.com/ZieIony/Carbon

以下图片和代码可以在 Carbon 的示例中找到。

enter image description here

代码:

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

相关文章:

java - JTable 中的 JSpinner(时间)

android - 如何在 Android studio 中禁用 android native 调试器

android - 使用 NotificationListenerService 时 getActiveNotifications 始终为 null

java - Soapui - 警告 - 未检测到文档的语法约束(DTD 或 XML 模式)

java - Scala 如何在方法定义中接收多个参数?

java - 在 selenium 的表中断言多个值

java - 如何防止直接 URL 访问 Android 应用程序中使用的文件?

java - BeanIO 的 Xml 映射,列表未正确解释

xml - 如何用插件打包我的 joomla 2.5 组件?

java - 在 Executor Service 的 ThreadPool 中添加线程