如何改变夏洛克操作栏文本颜色编程?文本、颜色、操作、夏洛克

2023-09-12 03:22:29 作者:凉城

如何改变从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.

 
精彩推荐
图片推荐