Dan*_*y C 30
以下是我在一次网络搜索后从Fred Grott(http://knol.google.com/k/fred-grott/advance-tabs/)找到的新答案.
这使您可以设置selector
文本颜色,以便在选择或不选择选项卡时可以使用不同的颜色.如果您为选项卡使用不同的背景颜色,这可能非常有用.当然,您也可以只使用普通颜色而不是选择器.
final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.color.text_tab_indicator));
Run Code Online (Sandbox Code Playgroud)
其中R.color.text_tab_indicator是位于res/drawable文件夹中的选择器xml文件.
换句话说,指示符文本实际上是可以通过可从对象访问的对象TextView
检索View
的TabWidget
.
请查看Fred的示例,了解有关变量声明以及其他技巧的更多信息和上下文.
Ale*_*voy 24
在自定义主题更改中设置样式
<item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item>
Run Code Online (Sandbox Code Playgroud)
和
<style name="Widget.TabWidget">
<item name="android:textAppearance">@style/TextAppearance.Widget.TabWidget</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
<style name="TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">@android:color/tab_indicator_text</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Sha*_*mam 20
Danny C的回答是100%正确的.我只想添加一些东西来完成资源文件的完整答案.
res/color文件下的text_tab_indicator
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:textColor="@color/text_tab_selected"
android:state_selected="true" />
<item android:textColor="@color/text_tab_unselected"
android:state_selected="false" />
</selector>
Run Code Online (Sandbox Code Playgroud)
此text_tab_unselected&text_tab_selected在colors/values文件夹下将如下所示
<resources>
<color name="text_tab_selected">#ffffff</color>
<color name="text_tab_unselected">#95ab45</color>
Run Code Online (Sandbox Code Playgroud)
之后,最后在tab类文件中添加Dannyy的答案
final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.color.text_tab_indicator));
Run Code Online (Sandbox Code Playgroud)
也可以在不使用java的情况下声明颜色的变化 - 这可能更好.
我对text_tab_indicator进行了更改(注意textColor已更改为'color'):
<?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>
Run Code Online (Sandbox Code Playgroud)
将TabWidget的样式设置为指向xml代码中的特定样式:
<TabWidget
...
style="@style/TabText"
/>
Run Code Online (Sandbox Code Playgroud)
声明您的text_tab_indicator位于/ res/color中,如您在样式中所需的颜色
<style name="TabText">
<item name="android:textColor">@color/tab_text_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力(对我来说).
干杯,兰德尔
归档时间: |
|
查看次数: |
66047 次 |
最近记录: |