我试图让 SampleTabsStyled demo来自 ViewPagerIndicator更改当前选定选项卡的文本颜色,但未成功。
但是,SampleTitlesStyledTheme demo在标题/标签之间切换时确实会改变其文本颜色。
查看 styles xml 内部时:
<resources>
...
<style name="CustomTitlePageIndicator">
<item name="android:background">#18FF0000</item>
<item name="footerColor">#FFAA2222</item>
<item name="footerLineHeight">1dp</item>
<item name="footerIndicatorHeight">3dp</item>
<item name="footerIndicatorStyle">underline</item>
<item name="android:textColor">#AA000000</item>
<item name="selectedColor">#FF000000</item>
<item name="selectedBold">true</item>
</style>
...
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:background">@drawable/custom_tab_indicator</item>
<item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
<item name="android:textColor">#FF555555</item>
<item name="android:textSize">16sp</item>
<item name="android:divider">@drawable/custom_tab_indicator_divider</item>
<item name="android:dividerPadding">10dp</item>
<item name="android:showDividers">middle</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:fadingEdge">horizontal</item>
<item name="android:fadingEdgeLength">8dp</item>
</style>
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
...
</resources>
我看到 SampleTitlesStyledTheme
演示使用 CustomTitlePageIndicator
样式,它定义了一个 selectedColor
项。所以(也许是天真地)我想补充一下
<item name="selectedColor">#FF000000</item>
对于 SampleTabsStyled
演示使用的样式,CustomTabPageIndicator
,但是,唉,这不起作用。
这个问题似乎很明显,但我还是会问:有没有办法(使用当前样式 xml)让 SampleTabsStyled
演示中标签的当前选定文本具有不同的颜色比其他标签?如果有,怎么做?
编辑
哦,我将它与 ActionBarSherlock 结合使用,以防万一这很重要...
最佳答案
假设您不介意创建额外的 xml,首先尝试在 CustomTabPageIndicator.Text
(或 CustomTabPageIndicator
中包含属性 android:textColor
>) 像这样:
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:textColor">@drawable/tab_text_color</item>
...
</style>
tab_text_color.xml
放在 res/drawable 文件夹下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:color="@color/text_tab_selected" />
<item
android:state_selected="false"
android:color="@color/text_tab_unselected" />
</selector>
最后,只需在位于的颜色资源文件 colors.xml
中定义两种颜色 @color/text_tab_selected
和 @color/text_tab_unselected
res/values 文件夹(如果它不存在,则创建一个)。例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="text_tab_selected">#FF000000</color>
<color name="text_tab_unselected">#FF555555</color>
</resources>
关于android - 使用 ViewPagerIndicator 为选定选项卡的文本赋予不同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16573230/