如何为安卓设计带有渐变和阴影的按钮?

3

我该如何在安卓中创建像下面这样的按钮?对于按钮的主要部分,我基本上已经做好了。但是我似乎无法弄清楚阴影和点击动画。

按钮

<Button
    android:text="Connect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/connectionStatus"
    android:layout_centerHorizontal="true"
    android:id="@+id/button"
    android:background="@drawable/button_background"
    android:minWidth="300dp"
    android:layout_marginTop="32dp"
    android:onClick="onClick"
    android:textColor="#fff"
    />

这里是可绘制对象。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#21D4FD"
        android:endColor="#B721FF"
        android:angle="45"
    />
    <corners android:bottomLeftRadius="20dip"
        android:topRightRadius="20dip"
        android:topLeftRadius="20dip"
        android:bottomRightRadius="20dip"
    />
</shape>

这是我目前拥有的内容:

What I have

这是我想要的内容:

What I want


关注阴影效果的高度。就按钮而言,您可能希望使用ImageButtons,并从诸如Photoshop之类的软件中嵌入渐变。 https://developer.android.com/training/material/shadows-clipping.html - AeriaGlorisia
2个回答

2

如果您想要给按钮添加渐变效果,可以尝试使用这个工具

如果想了解更多信息,请点击这里


0

我找到了解决方案,可以实现你图片中的4个按钮。我将一个库与自己的drawable结合起来,并使用了一个技巧,实现了你所寻找的Button。请查看this,这是我的秘诀:

My approach


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接