Android - 按钮边框 [英] Android - border for button
本文介绍了Android - 按钮边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何给按钮添加边框?是否可以在不使用图像的情况下做到这一点?
How do I add a border to a button? Is it possible to do this without resorting to use of images?
推荐答案
步骤 1:创建名为 my_button_bg.xml 的文件
Step 1 : Create file named : my_button_bg.xml
第 2 步:将此文件放入 res/drawables.xml
Step 2 : Place this file in res/drawables.xml
第 3 步:插入下面的代码
Step 3 : Insert below code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#00FF00"
android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#000000" />
</shape>
第 4 步:在需要的地方使用代码android:background="@drawable/my_button_bg",例如下面:
Step 4: Use code "android:background="@drawable/my_button_bg" where needed eg below:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Text"
android:background="@drawable/my_button_bg"
/>
这篇关于Android - 按钮边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文