且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为按钮背景颜色添加波纹效果到我的按钮?

更新时间:2023-01-26 23:34:06

对于想要将渐变背景,拐角半径和波纹效果加在一起的人来说,这是另一个可绘制的xml:

Here is another drawable xml for those who want to add all together gradient background, corner radius and ripple effect:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/colorPrimaryDark">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="@color/colorPrimaryDark" />
            <corners android:radius="@dimen/button_radius_large" />
        </shape>
    </item>

    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <gradient
                android:angle="90"
                android:endColor="@color/colorPrimaryLight"
                android:startColor="@color/colorPrimary"
                android:type="linear" />
            <corners android:radius="@dimen/button_radius_large" />
        </shape>
    </item>
</ripple>

将其添加到按钮的背景中.

Add this to the background of your button.

<Button
    ...
    android:background="@drawable/button_background" />