首页 > 代码库 > android 圆角边框、渐变背景的TextView
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节点配置四周圆角的半径。
android 圆角边框、渐变背景的TextView
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。