android 圆角边框、渐变背景的TextView

加一个红色的边框:

textView的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" 
  android:paddingLeft="20dp"
  android:paddingRight="20dp"
  >
  
  <!-- 通过android:background指定背景 -->
  <TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="带边框的文本"
    android:textSize="24sp"
    android:background="@drawable/bg_border"
    />

</LinearLayout>

边框XML:(新建文件夹drawable.然后在此文件夹下新建文件bg_border.xml)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
 
  <!-- 设置红色边框 -->
  <stroke android:width="2dp" android:color="#f00"/>
</shape>

效果

渐变颜色:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
 	<!-- 指定圆角矩形的4个圆角的半径 -->
 	<corners android:topLeftRadius="5dp"
 	    android:topRightRadius="5dp"
 	    android:bottomLeftRadius="5dp"
 	    android:bottomRightRadius="5dp"
 	    />
 	<!-- 指定边框线条的宽度和颜色 -->
 	<stroke android:width="4dp" android:color="#f0f"/>
 	
 	<!-- 指定使用渐变背景色,使用sweep类型的渐变,颜色从红色到绿色再到蓝色 -->
 	<gradient android:startColor="#f00"
 	     android:centerColor="#0f0"
 	    android:endColor="#00f"
 	    android:angle="270"
 	    android:centerX="0.5"
 	    android:centerY="0.5"
 	    
 	    />
</shape>

效果:

说明:

(1)shape节点配置的是图形的形式,主要包括方形、圆形等

(2)gradient节点主要配置起点颜色、终点颜色及中间点的颜色、坐标、渐变效果(0,90,180从左到右渐变,270从上到下渐变)默认从左到右。 

(3)corners节点配置四周圆角的半径。   


自:http://www.tuicool.com/articles/F7nE3y

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值