Comments (4)
在com.angcyo.tablayout.DslTabLayout#getTabLayoutConfig
对象DslTabLayoutConfig
中:
com.angcyo.tablayout.DslTabLayoutConfig#getTabSelectColor
com.angcyo.tablayout.DslTabLayoutConfig#getTabDeselectColor
触发重绘, 即可生效.
from dsltablayout.
在
com.angcyo.tablayout.DslTabLayout#getTabLayoutConfig
对象
DslTabLayoutConfig
中:
com.angcyo.tablayout.DslTabLayoutConfig#getTabSelectColor
com.angcyo.tablayout.DslTabLayoutConfig#getTabDeselectColor
触发重绘, 即可生效.
能重设所有选中和未选中的tab的字颜色吗?我试了下好像不行。
dslTabLayout.configTabLayoutConfig {
//选中view的回调
onSelectViewChange = { fromView, selectViewList, reselect ->
val toView = selectViewList.first()
}
//选中index的回调
onSelectIndexChange = { fromIndex, selectIndexList, reselect ->
val toIndex = selectIndexList.first()
if (tabIndex == 0) {
tl_news_article.tabLayoutConfig!!.tabSelectColor =
activity!!.getColorValue(R.color.white)
tl_news_article.tabLayoutConfig!!.tabDeselectColor =
activity!!.getColorValue(R.color.white)
} else {
tl_news_article.tabLayoutConfig!!.tabSelectColor =
activity!!.getColorValue(R.color.TextColorBlack)
tl_news_article.tabLayoutConfig!!.tabDeselectColor =
ContextCompat.getColor(activity!!, R.color.text_gray)
}
tl_news_article.invalidate()
}
}
我这边要这样的效果(有11个tabItem)第一个item时选中文字颜色和未选中都是白色(tablayout背景为透明)其他的第二个到第十一个选中文字颜色为黑色未选中文字颜色为灰色。
from dsltablayout.
根据您的描述, 以下代码能帮助您:
tabLayout.apply {
configTabLayoutConfig {
onSelectIndexChange = { fromIndex, selectIndexList, reselect ->
val toIndex = selectIndexList.first()
if (toIndex < 3) {
tabSelectColor = Color.WHITE
tabDeselectColor = Color.parseColor("#999999")
} else {
tabSelectColor = Color.RED
tabDeselectColor = Color.YELLOW
}
tabLayout.dslSelector.updateStyle()
}
}
}
注意tabLayout.dslSelector.updateStyle()
这个是生效的关键,而非invalidate
,之前回复有问题.
Demo
代码已更新, 可以fetch
查看一下.
from dsltablayout.
根据您的描述, 以下代码能帮助您:
tabLayout.apply { configTabLayoutConfig { onSelectIndexChange = { fromIndex, selectIndexList, reselect -> val toIndex = selectIndexList.first() if (toIndex < 3) { tabSelectColor = Color.WHITE tabDeselectColor = Color.parseColor("#999999") } else { tabSelectColor = Color.RED tabDeselectColor = Color.YELLOW } tabLayout.dslSelector.updateStyle() } } }注意
tabLayout.dslSelector.updateStyle()
这个是生效的关键,而非invalidate
,之前回复有问题.
Demo
代码已更新, 可以fetch
查看一下.
ok效果实现了,感谢解答!
from dsltablayout.
Related Issues (20)
- 怎么让文字不居中变大? HOT 4
- 我用代码add方式添加的item 怎么用代码方式设置高凸高度呢 HOT 1
- jenkins 打包无法下载依赖 HOT 1
- 动态修改某一项item HOT 4
- 不知道为啥,更新版本后一直拉不下来 HOT 1
- Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. HOT 4
- 远程引入viewpager绑定库后,TabLayout样式出现问题 HOT 1
- 支持tab双击事件 HOT 1
- 垂直方向动态添加子view后,indicator线不会显示出来。xml里面添加则无此问题 HOT 1
- 关于Item是否等宽 问题 HOT 1
- 中文问题 HOT 3
- 发现个问题。
- 代码 HOT 1
- 果断放弃 HOT 2
- 加油吧,老铁 HOT 1
- 怎么设置item的间距 HOT 1
- 请问怎么直接设置tab item垂直居中呢,我现在还得外面包一层,有点麻烦,能否框架提供这么个属性 HOT 1
- 如何修改某个Item的文本? HOT 1
- 请问能自定义TextView的Scale动画么 HOT 4
- demo写的读起来费死老劲了 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dsltablayout.