How to change selected Tab Text color using TabLayout from code in Android?

后端 未结 8 935
悲哀的现实
悲哀的现实 2020-12-13 01:58

\"enter

I\'m using android.support.widget.TabLayout

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 02:29

    It's better if you update the library with "com.google.android.material:material:1.0.0". Then use bellow code,

    In XML attributes

    
    

    In Kotlin programmatically

    (tab_layout as TabLayout).setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorPrimary))
    (tab_layout as TabLayout).setSelectedTabIndicatorColor(ContextCompat.getColor(mContext, R.color.white))
    (tab_layout as TabLayout).setTabTextColors(ContextCompat.getColor(mContext, R.color.white),
                    ContextCompat.getColor(mContext, R.color.white))
    

提交回复
热议问题