首页 > 解决方案 > 在 XML 中可以用两种以上的颜色绘制吗?

问题描述

在此处输入图像描述

如何在 XML android 中的 drawable 中实现这一点?底部是透明的。

标签: androidandroid-layout

解决方案


在 XML 中的 drawable 中实现这一点。

首先,您需要创建一个可绘制文件。

然后,添加这些代码行。

<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#00000000">

<item>

    <shape android:shape="rectangle">

        <padding
            android:left="10dp"
            android:right="10dp"/>

        <gradient
            android:startColor="@color/purple_500"
            android:endColor="@color/purple_200"
            android:angle="0"/>

    </shape>

</item>

<item>

    <shape android:shape="rectangle">

        <gradient
            android:startColor="@color/white"
            android:angle="90"/>

    </shape>

</item>

</ripple>

然后在android中的任何地方使用drawable文件。

它看起来如何。


推荐阅读