圆角边框,渐变背景的Textview

来源:互联网 发布:js手册中文版 编辑:程序博客网 时间:2024/05/22 10:22

在默认情况下,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="圆角渐变" />
效果图如下:





1 0
原创粉丝点击