Android TextView渐变颜色和方向及动画效果的设置详解
作者:Lucky_William 时间:2022-06-13 09:23:58
GradientTextView
Github点我
一个非常好用的库,使用kotlin实现,用于设置TexView的字体 渐变颜色、渐变方向 和 动画效果
添加依赖
之前仓库发布在 jcenter,但是因为它即将不可用,近期已完成迁移。建议大家使用 mavenCentral 的配置。
使用 jcenter
implementation 'com.williamyang:gradienttext:1.0.1'
使用 mavenCentral
buildscript {
repositories {
mavenCentral()
}
}
implementation 'io.github.weilianyang:gradienttext:1.0.1'
效果预览:
一、控件样式
<declare-styleable name="GradientTextView">
<attr name="gradient_startColor" format="reference|color" />
<attr name="gradient_endColor" format="reference|color" />
<attr name="gradient_direction" format="enum">
<enum name="leftToRight" value="1" />
<enum name="topToBottom" value="2" />
</attr>
<attr name="gradient_animate" format="boolean" />
<attr name="gradient_speed" format="enum">
<enum name="slow" value="20" />
<enum name="normal" value="10" />
<enum name="fast" value="5" />
</attr>
</declare-styleable>
二、属性介绍
属性 | 可选值 | 作用 |
---|---|---|
gradient_startColor | 值在color.xml中定义 | 渐变颜色的起始值(默认值:#6200EE) |
gradient_endColor | 值在color.xml中定义 | 渐变颜色的结束值(默认值:#03DAC5) |
gradient_direction | leftToRight:从左向右,topToBottom:从上向下 | 渐变颜色的方向(默认值:leftToRight) |
gradient_animate | true or false | 渐变颜色的动画开关(默认值:false) |
gradient_speed | slow、normal、fast | 渐变颜色的动画速度(默认值:normal) |
三、控件在布局中使用
<com.william.gradient.GradientTextView
android:id="@+id/gradientTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/leftToRight_GradientTextView"
android:textSize="24sp"
app:gradient_animate="true"
app:gradient_direction="leftToRight"
app:gradient_speed="normal" />
四、在代码中控制动画开关
gradientTextView.apply {
translateAnimate = !translateAnimate
invalidate()
}
来源:https://blog.csdn.net/java_android_man/article/details/107290786
标签:Android,TextView,渐变颜色,动画效果
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C语言实现超市计价收款系统
2021-08-21 17:56:47
![](https://img.aspxhome.com/file/2023/2/129542_0s.jpg)
Android编程实现读取本地SD卡图片的方法
2023-01-10 01:32:30
Java多线程锁机制相关原理实例解析
2023-05-25 12:33:37
![](https://img.aspxhome.com/file/2023/0/96110_0s.png)
Maven 生成打包可执行jar包的方法步骤
2023-01-02 14:53:15
![](https://img.aspxhome.com/file/2023/2/66192_0s.jpg)
java web手写实现分页功能
2022-02-04 02:23:15
![](https://img.aspxhome.com/file/2023/8/63028_0s.jpg)
Android自定义Dialog实现加载对话框效果
2022-04-19 12:16:06
![](https://img.aspxhome.com/file/2023/6/137226_0s.gif)
android studio 项目 :UI设计高精度实现简单计算器
2022-07-14 02:09:29
![](https://img.aspxhome.com/file/2023/2/98622_0s.png)
java求数组元素重复次数和java字符串比较大小示例
2023-08-04 22:20:02
SpringBoot 多Profile使用与切换方式
2022-04-13 14:58:27
![](https://img.aspxhome.com/file/2023/1/78951_0s.png)
Java实现三子棋小游戏
2022-09-12 01:27:20
C#读取二进制文件方法分析
2022-04-23 11:17:43
Java枚举详解及使用实例(涵盖了所有典型用法)
2023-06-29 23:17:55
C#预定义的基础类型转换
2023-08-13 03:14:16
![](https://img.aspxhome.com/file/2023/8/69788_0s.png)
C#编程之事务用法
2023-08-20 05:50:37
Java图像之自定义角度旋转(实例)
2023-10-07 21:04:28
Java女装商城系统的实现流程
2023-09-23 11:53:51
![](https://img.aspxhome.com/file/2023/5/81255_0s.png)
Java System类两个常用方法代码实例
2023-02-01 13:52:15
![](https://img.aspxhome.com/file/2023/8/71238_0s.png)
SpringCloud2020整合Nacos-Bootstrap配置不生效的解决
2023-11-29 02:42:47
c#调用api控制windows关机示例(可以重启/注销)
2021-12-20 14:52:06
利用logback filter过滤某个类 屏蔽某个类
2023-07-25 20:38:08
![](https://img.aspxhome.com/file/2023/3/108443_0s.png)