tablayout change tab selected textsize
tablayout change tab selected textsize
Tablayout.tab cant change selected textsize in code
.
textAppearance can't set selectTextsize too.so how complete it?
试试下面的方法。注意也要实现选项卡选择的侦听器。
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?) {}
}
Tablayout.tab cant change selected textsize in code
.
textAppearance can't set selectTextsize too.so how complete it?
试试下面的方法。注意也要实现选项卡选择的侦听器。
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?) {}
}