Arc*_*pgc 3 android actionbarsherlock
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);
Run Code Online (Sandbox Code Playgroud)
截至目前,每个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>
Run Code Online (Sandbox Code Playgroud)
我试着用
<item name="textColor">@color/black</item>
Run Code Online (Sandbox Code Playgroud)
但它给我一个错误,textColor不是一个有效的属性
谢谢
Tom*_*mik 15
您不应该从代码中更改文本颜色.请改用颜色状态列表资源.
在资源中定义颜色选择器.在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>
Run Code Online (Sandbox Code Playgroud)
然后在样式中设置文本颜色:
<item name="android:textColor">@color/my_color_selector</item>
Run Code Online (Sandbox Code Playgroud)
编辑:
您必须在样式中的正确位置设置文本颜色!设置textColor (android:)actionBarTabTextStyle.主题必须包含:
<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>
Run Code Online (Sandbox Code Playgroud)
然后在选项卡文本样式中设置文本颜色:
<style name="MyTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText" >
<item name="android:textColor">@color/my_color_selector</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4656 次 |
| 最近记录: |