如何给按钮添加边框?能否在不使用图片的情况下实现?
如何给按钮添加边框?能否在不使用图片的情况下实现?
<?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"/>
输出 - 将是带有渐变和边框的按钮。
注 - 您可以根据需要更改按钮的十六进制代码,也可以更改描边宽度。