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节点配置四周圆角的半径。

时间: 2024-07-30 00:09:00

android 圆角边框、渐变背景的TextView的相关文章

android圆角矩形有背景颜色

android 圆角矩形,渐变颜色,自定义 首先,在drawable目录下写一个xml,名字随便起(只要符合规范),代码如下: <span style="color:#009900;"><span style="background-color: rgb(255, 255, 255);"><?xml version="1.0" encoding="utf-8"?> <shape xml

圆角边框和渐变

Demo2\aa\src\main\res\drawable\bg_border.xml 1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android"> 3 <!--设置背景色为透明色--> 4 <solid android:color="#

边框与背景颜色

此次随笔记录,讲述在同时有边框.背景颜色,且颜色都带透明度时相互的影响. 问题的思考源于想要用圆角边框和背景,制作图片轮播的圆形按钮. 由于按钮需要在图片上方显示,所以为了减轻对图片的遮挡,改善视觉效果,需要给边框和背景加上透明度,于是我是这么写的 1 li{ 2 width: 18px; 3 height: 18px; 4 margin-left: 10px; 5 display: inline-block; 6 border-radius: 50%; 7 border:2px solid;

Android给TextView和EditText等控件设置透明背景、圆角边框

第一种方法:在drawable文件夹下新建一个文件设置背景样式 代码: 在drawable文件夹下面新建textviewborder.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#80858

Android给TextView设置透明背景、圆角边框

第一种方法:在drawable文件夹下新建一个文件设置背景样式 代码: 在drawable文件夹下面新建text_view_border.xml [java] view plaincopy <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid an

【Android UI】案例02 圆角边框、圆角背景的实现(shape)

本文主要分享圆角边框与圆角背景的实现方式.该方式的实现,需要了解shape的使用,该部分的详细介绍,请阅读博客http://blog.csdn.net/mahoking/article/details/23672271.文中有较详细的介绍. [转载使用,请注明出处:http://blog.csdn.net/mahoking] 如下是演示的shape_layout.xml模板. <?xml version="1.0" encoding="utf-8"?>

android 使用xml为背景添加渐变,描边,圆角的效果

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#40E0D0"/> <!-- 渐变 --> <gradient android:startColor="#E

CSS3下不一样的阴影、背景和圆角边框样式

CSS3下不一样的阴影.背景和圆角边框样式 CSS2.1 发布至今已有7年的历史.CSS3的出现就是增强CSS2.1的功能,减少图片的使用次数以及解决HTML页面上的特殊效果 当前,CSS3技术最适合在移动Web开发中使用的特性包括: ●增强的选择器 ●阴影 ●强大的背景设置 ●圆角边框 阴影: 现在的CSS3样式已经支持阴影样式效果.目前可使用的阴影的效果分为两种:文本内容的阴影效果和元素的阴影效果. box-shadow CSS3的box-shadow属性是让元素具有阴影的效果,其语法如下:

50个Android开发技巧(12 为控件加入圆角边框)

控件的圆角边框能够使你的App看起来更美观,事实上实现起来也非常easy. (原文地址:http://blog.csdn.net/vector_yi/article/details/24463025) 以创建一个灰色的带圆角边框的Button为例: 一.创建一个ShapeDrawable作为背景 在drawable文件夹下创建一个button_rounded_background.xml文件: <shape xmlns:android = "http://schemas.android.c