安卓 - 按钮边框

253

如何给按钮添加边框?能否在不使用图片的情况下实现?


同样的方式,如此:https://dev59.com/cVvUa4cB1Zd3GeqPxdY2#7626628 - asenovm
11个回答

0
在您的drawable文件夹中创建一个名为gradient_btn的drawable文件,并粘贴下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#7BF8C6"
    android:centerColor="#9DECAD"
    android:endColor="#7BF8C6"
    android:angle="270" />
<corners
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp"
    android:bottomLeftRadius="15dp"
    android:bottomRightRadius="15dp"
    />
<stroke android:width="3px" android:color="#000000" />

</shape>

然后在你的xml中的Button代码中调用你创建的文件:

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:background="@drawable/gradient_btn"/>

输出 - 将是带有渐变和边框的按钮。

注 - 您可以根据需要更改按钮的十六进制代码,也可以更改描边宽度。


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