如何为TextView添加边框

首先大家需要知道一个概念:android:background的值是一个xml文件。这就意味着如果我们想要一个框,就要定义一个xml布局文件,然后把布局文件的内容赋给TextView的background属性。

操作步骤如下:

第一步:定义xml文件,命名为setbar_bg.xml,并写入如下代码:

<?xml version="1.0" encoding="UTF-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    //背景色
    <solid android:color="#00000000"/>

    //边框宽度,颜色
    <stroke android:width="2dip" android:color="#ff000000" />

</shape>

第二部,把xml布局放入drawable文件目录下,同时赋给background属性

android:background="@drawable/setbar_bg"

然后就成功了

发布了113 篇原创文章 · 获赞 33 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_38367681/article/details/84035405