【发布时间】:2017-02-22 00:33:24
【问题描述】:
【问题讨论】:
-
您是否在xml中设置了TabLayout的样式?请在您的问题中包含 xml。
-
当然我在xml中设置了TabLayout的样式,但是如果选择了我想改变标签文本大小,它只能设置一个固定文本大小。
标签: android android-support-library android-tablayout
【问题讨论】:
标签: android android-support-library android-tablayout
试试下面的。请注意实现选项卡选择的侦听器。
TextView title = (TextView)(((LinearLayout ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(tabPosition)).getChildAt(1));
title.setTextSize(...);
【讨论】:
class OnTabSelectedListener implements TabLayout.OnTabSelectedListener{
@Override
public void onTabSelected(TabLayout.Tab selectedTab) {
LinearLayout tabLayout1 = (LinearLayout)((ViewGroup) tabLayout.getChildAt(0)).getChildAt(selectedTab.getPosition());
TextView tabTextView = (TextView) tabLayout1.getChildAt(1);
// tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.BOLD);
tabTextView.setTextSize(20);
}
@Override
public void onTabUnselected(TabLayout.Tab unselectedTab) {
LinearLayout tabLayout1 = (LinearLayout)((ViewGroup) tabLayout.getChildAt(0)).getChildAt(unselectedTab.getPosition());
TextView tabTextView = (TextView) tabLayout1.getChildAt(1);
//tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.NORMAL);
tabTextView.setTextSize(15);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
}
用 textview 做任何事情都可以享受....
【讨论】:
显示粗体字
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?) {}
}
【讨论】: