前言
上一篇介绍了文字变色的原理,本篇文章就简单介绍下其应用。原理都掌握了,应用还不是手拿把掐😁
重学 Android 自定义 View 系列(四):文字变色
最终效果如下:
1. 结构分析
- 指示器:配合Viewpage显示界面标签,这里的指示器由于要用到我们的
ColorTrackTextView
,所以需要自定义,动态添加。 - ViewPage:通过监听界面滚动信息,设置指示器文字变色。
2. 代码实现
指示器为 LinearLayout
,动态添加ColorTrackTextView
val items: List<String> by lazy {
listOf("首页", "关注", "附近", "我的")
}
private val mIndicators: ArrayList<ColorTrackTextView> by lazy {
ArrayList() }
private fun initIndicator() {
items.forEachIndexed {
index, s ->
//动态添加颜色跟踪的TextView
v