Android——具有边框的Textview

我们可以看见很多类似瀑布流的分类:

通过边框进行选择,那么这个边框是怎么变成的呢? 我们可以通过添加背景图,不过有更加简单的,如下:

我们在drawable文件中编写一个shape,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#fc1f65"/>
</shape>

最后在xml布局文件中bg中加入:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_margin="5dp"
android:background="@drawable/textview_border"
android:text="程序员"
android:gravity="center"
android:textColor="@color/text_color" />

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_margin="5dp"
android:background="@drawable/textview_border"
android:text="工程师"
android:gravity="center"
android:textColor="@color/text_color" />
</LinearLayout>

怎么样还不错吧!我们还可以进行拓展比如边框的角变得圆润点,或是颜色修改,或者点击之后改变颜色!

转载于:https://www.cnblogs.com/llw1996/p/7232406.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值