【问题标题】:How to set a Gradient Background Color to a Card (from Material Components)如何为卡片设置渐变背景颜色(来自 Material Components)
【发布时间】:2020-07-15 12:09:15
【问题描述】:

我想知道是否有任何方法可以从材质组件中为卡片设置渐变背景颜色。我正在阅读docs,,但我找不到任何东西。

【问题讨论】:

  • 类似于this的东西?
  • 虽然Card 是一个 ViewGroup,但它是不同的。

标签: android material-components-android material-components


【解决方案1】:

在 res/drawable 下创建一个 xml 并将你的 cardview 的背景设置为这个 xml。

 <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="rectangle"
            xmlns:android="http://schemas.android.com/apk/res/android">
    
        <gradient
                android:startColor="@color/colorPurple"
                android:endColor="@color/colorBlue"
                android:angle="0"/>
    
    </shape>

【讨论】:

    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    相关资源
    最近更新 更多