android– 如何更改ActionBarSherlock选项卡文本颜色?

android– 如何更改ActionBarSherlock选项卡文本颜色?,第1张

概述adapter.addTab(getSupportActionBar().newTab().setText("Tab-1"),Tab1.class,null);adapter.addTab(getSupportActionBar().newTab().setText("Tab-2"),Tab2.class,null);adapter.addTab(getSupportActionBar().

adapter.addTab(getSupportActionbar().newTab().setText("Tab-1"),                Tab1.class, null);adapter.addTab(getSupportActionbar().newTab().setText("Tab-2"),                Tab2.class, null);adapter.addTab(getSupportActionbar().newTab().setText("Tab-3"),                Tab3.class, null);

截至目前,每个Tab的Textcolor都是白色的.我希望它在未选中时为灰色,在选中时为白色.那么,我如何更改onTabSelected或onTabUnselected中的文本颜色.

或者我应该使用setCustomVIEw作为选项卡?在这里,TextSize和所有这些都需要处理

<style name="my_ActionbarTabStyle" parent="@style/Widget.Sherlock.Actionbar.TabVIEw">    <item name="background">@drawable/tab_indicator_ab_wicfy</item>    <item name="androID:background">@drawable/tab_indicator_ab_wicfy</item>    <item name="androID:textcolor">@color/black</item></style>

我试着用

<item name="textcolor">@color/black</item>

但它给我一个错误,textcolor不是一个有效的属性

谢谢

解决方法:

您不应该从代码中更改文本颜色.请改用color state list resource.

在资源中定义颜色选择器.在res / color /目录中定义xml文件.该文件将包含:

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <!-- use when selected -->    <item androID:state_selected="true" androID:color="#fff" />    <!-- otherwise use -->    <item androID:color="#888" /></selector>

然后在样式中设置文本颜色:

<item name="androID:textcolor">@color/my_color_selector</item>

编辑:

您必须在样式中的正确位置设置文本颜色!在(androID:)actionbarTabTextStyle中设置textcolor.主题必须包含:

<style name="Mytheme" parent="theme.Sherlock.light.DarkActionbar">    ...    <!-- define text style for tabs -->    <item name="actionbarTabTextStyle">@style/MyTabTextStyle</item>    <item name="androID:actionbarTabTextStyle">@style/MyTabTextStyle</item>    ...</style>

然后在选项卡文本样式中设置文本颜色:

<style name="MyTabTextStyle" parent="Widget.Sherlock.Actionbar.TabText" >    <item name="androID:textcolor">@color/my_color_selector</item></style>
总结

以上是内存溢出为你收集整理的android – 如何更改ActionBarSherlock选项卡文本颜色?全部内容,希望文章能够帮你解决android – 如何更改ActionBarSherlock选项卡文本颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1120040.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存