Code Monkey home page Code Monkey logo

Comments (4)

angcyo avatar angcyo commented on July 30, 2024

com.angcyo.tablayout.DslTabLayout#getTabLayoutConfig

对象DslTabLayoutConfig 中:

com.angcyo.tablayout.DslTabLayoutConfig#getTabSelectColor

com.angcyo.tablayout.DslTabLayoutConfig#getTabDeselectColor

触发重绘, 即可生效.

from dsltablayout.

YumikoAzu avatar YumikoAzu commented on July 30, 2024

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.

angcyo avatar angcyo commented on July 30, 2024

根据您的描述, 以下代码能帮助您:

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.

YumikoAzu avatar YumikoAzu commented on July 30, 2024

根据您的描述, 以下代码能帮助您:

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.