如何更改android中选项卡指示器文本的颜色?
如何更改选项卡文本指示器的颜色?我可以使用参考示例的选择器标签更改图标。但不能改变文字颜色。如何?
how to change the color of the text indicator of tab? i can change the icon using selector tag refered the example. but cant to the text color. how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
颜色的变化也可以在不使用 java 的情况下表示 - 这可能更好。
我对 text_tab_indicator 进行了更改(注意 textColor 已更改为“颜色”):
将 TabWidget 的样式设置为指向 xml 代码中的特定样式:
将位于 /res/color 中的 text_tab_indicator 声明为您想要的样式颜色
它就像一个魅力(对我来说)。
干杯,
兰德尔
The change in color can also be stated without using java - which is probably better.
I made changes to the text_tab_indicator (notice textColor was changed to 'color'):
Set the style of the TabWidget to point to a specific style in your xml code:
Declare your text_tab_indicator located in /res/color as you desired color in the style
It worked like a charm (for me).
Cheers,
Randall
Danny C的答案是100%正确的。我只是想添加一些东西来用资源文件做出完整的答案。
res/color 文件下的text_tab_indicator
以及这个text_tab_unselected & text_tab_selected 在颜色/值文件夹下看起来像这样
最后在选项卡类文件中添加 Dannyy 的答案
Danny C's answer is 100% correct.I just wanted to add something to it to make a complete answer with resource file.
The text_tab_indicator under res/color file
And this text_tab_unselected & text_tab_selected will look like this under colors/values folder
After that finally add Dannyy's answer in tab class file
风格它
在您的自定义主题更改中
和
Style it
in your custom theme change
and
这是我从 Fred Grott 那里找到的一个新答案(http://knol.google .com/k/fred-grott/advance-tabs/)经过一些网络搜索后。
这可以让您为文本颜色设置一个
选择器
,以便在选择或不选择选项卡时可以使用不同的颜色。如果您选择选项卡使用不同的背景颜色,这将非常有用。当然,您也可以只添加纯色而不添加选择器。其中 R.color.text_tab_indicator 是 选择器 xml 文件位于您的 res/drawable 文件夹中。
换句话说,指示符文本实际上是一个
TextView
,可通过View
对象检索,该对象可从TabWidget
对象访问。查看 Fred 的示例,了解有关变量声明以及其他技巧的更多信息和上下文。
Here is a new answer I found from Fred Grott (http://knol.google.com/k/fred-grott/advance-tabs/) after a little web searching.
This lets you set a
selector
for text color so a different color can be used when tab is selected or not. Which can be very useful if you are using a different background color for the tab if its selected. Of course you can also just throw in a plain color and not a selector.Where R.color.text_tab_indicator is a selector xml file located in your res/drawable folder.
In other words, the indicator text really is a
TextView
which is retrievable via theView
object which can be accessed from theTabWidget
object.Take a look at Fred's examples for more info and context regarding the variable declarations as well as other tricks.