tablayout更改选项卡选择文本化

时间:2016-10-13 03:03:04

标签: android android-support-library android-tablayout

enter image description here

  

Tablayout.tab无法更改代码中的选定文本大小

enter image description here

  

textAppearance也不能设置selectTextsize。那怎么完成呢?

3 个答案:

答案 0 :(得分:0)

尝试以下内容。注意实现选项卡选择的侦听器。

TextView title = (TextView)(((LinearLayout ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(tabPosition)).getChildAt(1));
title.setTextSize(...);

答案 1 :(得分:0)

res/xml

使用textview做任何事情享受......

答案 2 :(得分:0)

显示粗体文本

tabLayout.addOnTabSelectedListener(tabSelectedListener)

private val tabSelectedListener = object : TabLayout.OnTabSelectedListener {
  override fun onTabSelected(tab: TabLayout.Tab?) {
    tab?.view?.children?.forEach {
      if (it is TextView) {
        it.post {
          it.setTypeface(ResourcesCompat.getFont(context, R.font.bold_font_name), Typeface.NORMAL)
        }
      }
    }
  }

  override fun onTabUnselected(tab: TabLayout.Tab?) {
    tab?.view?.children?.forEach {
      if (it is TextView) {
        it.post {
          it.setTypeface(ResourcesCompat.getFont(context, R.font.font_name), Typeface.NORMAL)
        }
      }
    }
  }

  override fun onTabReselected(tab: TabLayout.Tab?) {}
}