问题描述
我如何选择选项卡的字样大胆SlidingTabLayout?我发现设置所选标签颜色不够的问题,但在设置所选标签字样没有。先谢谢了。
How do I make selected tab's Typeface bold in SlidingTabLayout? I found enough questions on setting the selected tab colour, but none on setting the selected tab Typeface. Thanks in advance.
推荐答案
我终于成功,如下所示:
I finally managed it as follows:
在 onPageScrolled()
方法进行以下更改:
View selectedTitle = mTabStrip.getChildAt(position);
View leftOfSelected = mTabStrip.getChildAt(position-1);
View rightOfSelected=null;
if (position<=tabStripChildCount-1) {
rightOfSelected = mTabStrip.getChildAt(position + 1);
}
if (selectedTitle != null) {
TextView selectedText = (TextView) selectedTitle;
TextView leftOfSelectedText = (TextView) leftOfSelected;
TextView rightOfSelectedText = (TextView) rightOfSelected;
if (position > 0 && position < tabStripChildCount - 1) {
selectedText.setTypeface(Typeface.DEFAULT_BOLD);
leftOfSelectedText.setTypeface(Typeface.DEFAULT);
rightOfSelectedText.setTypeface(Typeface.DEFAULT);
} else if (position == 0) {
selectedText.setTypeface(Typeface.DEFAULT_BOLD);
rightOfSelectedText.setTypeface(Typeface.DEFAULT);
} else if (position == tabStripChildCount - 1) {
selectedText.setTypeface(Typeface.DEFAULT_BOLD);
leftOfSelectedText.setTypeface(Typeface.DEFAULT);
}
}
同样, scrollToTab()
方法可以使用相同的code片段如上编辑。所有你需要做的是替换 selectedTitle
与 selectedChild
和位置
与的tabIndex
。如果你想更好的UI响应,你也可以做同样的使用onPageSelected()
方法。不过,别忘了重新声明 tabStripChildCount
。
Similarly, the scrollToTab()
method can be edited with the same code snippet as above. All you need to do is replace selectedTitle
with selectedChild
and position
with tabIndex
. If you want better UI response, you may also do the same in onPageSelected()
method. Just remember to re-declare tabStripChildCount
.
干杯!
这篇关于Android的SlidingTabLayout选定的选项卡粗体字样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!