如何改变夏洛克操作栏文本颜色编程? [英] How to change Sherlock action bar text color programatically?

查看:85
本文介绍了如何改变夏洛克操作栏文本颜色编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变从Java code中的操作栏的选项卡文本颜色?无法切换到一个XML文件中定义不同的主题,但类似.setTextColor(Color.GREEN)。

How can you change the tab text color of the action bar from Java code? Not switching to a different theme that was defined in an XML file, but something like .setTextColor(Color.GREEN).

如果有一种方式来获得当前(不定制)来看,也许我可以尝试抓住TextView的从那里和改变它。

If there were a way to get the current (not custom) view, maybe I could try grabbing the TextView from there and changing it.

推荐答案

想通了....你可以通过在SpannableString:

Figured it out.... You can pass in a SpannableString:

SpannableString spannable = new SpannableString(myString);
spannable.setSpan(new ForegroundColorSpan(Color.GREEN), 0, myString.length(), 0);
myTextView.setText(spannable);

也许与标准操作栏这就够了(没试过),但对夏洛克你还需要静态设置的XML作为萨姆回答。否则,福尔摩斯似乎忽略跨度颜色。这不要紧,你在XML什么颜色设置,因为跨度颜色将被使用。

Maybe with the standard action bar this is enough (haven't tried), but for Sherlock you also need to set it statically in xml as Sam answered. Otherwise, Sherlock seemed to ignore the span color. It doesn't matter what color you set in the xml since the span color will be used instead.

这篇关于如何改变夏洛克操作栏文本颜色编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆