【发布时间】:2014-12-09 08:23:58
【问题描述】:
我正在使用来自 google (https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html) 的 SlidingTabLayout。
效果很好,但我想要的是将所选标题以粗体和不同颜色显示...
关于这篇文章: Custom unselected tab text color in SlidingTabLayout
我用选择器在 drawable 中创建了一个 text_tab.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/selected" android:state_selected="true" />
<item android:color="@android:color/unselected" />
</selector>
当我放入 populateTabStrip() 方法时
tabTitleView.setTextColor(getResources().getColorStateList(R.drawable.text_tab));
颜色始终是未选中的颜色...
我可能做错了什么,或者可能有另一种方法来自定义选定的标签标题。
有人有想法吗?
谢谢
【问题讨论】:
-
嗨!感谢您的提问,但您对所选的粗体标题有答案吗?
-
在 onPageSelected() 方法中,我只是添加了一个名为 updateTab(position) 的方法。在这种方法中,我正在检查所有选项卡,对于所选位置的选项卡,我正在更新颜色并将字体更改为粗体。