如何创建渐变边框颜色

时间:2021-06-13 02:52:58

标签: android android-drawable android-vectordrawable

我正在寻找诸如下面的按钮之类的东西:

enter image description here

我知道如何像这样创建它,但我想要它带有渐变边框颜色。

1 个答案:

答案 0 :(得分:1)

试试这个:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <!-- create gradient you want to use with the angle you want to use -->
        <shape android:shape="rectangle">
            <gradient
                android:angle="0"
                android:centerColor="@android:color/holo_blue_bright"
                android:endColor="@android:color/holo_red_light"
                android:startColor="@android:color/holo_green_light" />
            <corners android:radius="@dimen/dp_10"/>

        </shape>
    </item>
    <!-- create the stroke for top, left, bottom and right with the dp you want -->
    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp">
        <shape android:shape="rectangle" >
            <!-- fill the inside in the color you want (could also be a gradient again if you want to, just change solid to gradient and enter angle, start, maybe center, and end color) -->
            <solid android:color="#fff" />
            <corners android:radius="@dimen/dp_10"/>
        </shape>
    </item>

</layer-list>

选择你想要的颜色..