您的位置:首页 > 其它

圆角边框,渐变背景的Textview

2017-01-10 15:37 190 查看
在默认情况下,TextView是不带边框的,如果想为Textview添加边框,只能通过为它设置一个背景Drawable,改Drawble只是一个边框,这样就实现了带边框的TextView

第一步:创建shape XML文件 border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<!--设置背景颜色为橙色-->
<solid android:color="#daa447"></solid>
<!--设置边框颜色为红色-->
<stroke android:width="4dp" android:color="#f00"></stroke>
</shape>


第二步 在TextView中引入背景border.xml

<TextView
android:textSize="50sp"
android:background="@drawable/border"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带边框的文本" />

效果图如下:



设置圆角渐变的TextView

第一步:在Drawable创建bg.xml 文件

如下所示

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--设置圆角的半径-->
<corners android:radius="50dp"></corners>

<!--指定使用渐变背景色 颜色从红色-绿色-蓝色-->
<gradient
android:centerColor="#0f0"
android:endColor="#00f"
android:startColor="#f00"></gradient>
</shape>

第二步:在TextView中引入

<TextView
android:textSize="50sp"
android:background="@drawable/bg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="圆角渐变" />

效果图如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: