
正文
android的渐变色,Android渐变色
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
android怎么设置字体渐变色 不是背景渐变
●使用XML的方式为背景添加渐变效果
1、在res/drawable文件夹里添加一个jbshape.xml文件,然后写入如下代码:
?xml version="1.0" encoding="utf-8"?
gradient
android:angle="270"
android:centerColor="#00FFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#666666"
android:startColor="#0099FF" /
padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" /
corners android:radius="4dp" /
/shape
说明:
(1)shape节点配置的是图形的形式,主要包括方形、圆形等,上边代码为方形。
(2)gradient节点主要配置起点颜色、终点颜色及中间点的颜色、坐标、渐变效果(0,90,180从左到右渐变,270从上到下渐变)默认从左到右。
(3)corners节点配置四周圆角的半径。
相关问答
Q1: android 怎么自定义颜色渐变
1.在res/drawable/里新建XML文件(background_color.xml)
内容:
?xml version="1.0" encoding="UTF-8"?
shape xmlns:android=""
gradient
android:startColor="#000000"
android:endColor="#FFFFFF"
android:angle="90"
/
/shape
备:angle(角度)的值只可为:45 90 135 180等45的倍数
2.在res/layout里使用时:
颜色设置段:Android:src="@drawable/background_color
Q2: Android TextView 渐变色
简单的实现方式:
/**
* 设置TextView 的颜色渐变
*/
public void setTextViewStyles(TextView text) {
// LinearGradient 前四个参修改可以有不同的方向哦
LinearGradient mLinearGradient =new LinearGradient(0, 0, 0,
text.getPaint().getTextSize(), Color.parseColor("#FFD800"),
Color.parseColor("#FFC107"), Shader.TileMode.CLAMP);
text.getPaint().setShader(mLinearGradient);
text.invalidate();
}
写在最后: 方式有很多种, 我就不一一列举啦~ 谢谢


![[git]解决rebase冲突 [git]解决rebase冲突](https://www.04ip.com/template/qe/style/noimg/14.jpg)


