How to change Sherlock action bar text color programatically?

六眼飞鱼酱① 提交于 2020-01-15 16:39:11

问题


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).

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


回答1:


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);

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.




回答2:


I don't believe there is a method that controls this. However read this question: ActionBar text color

The best answer has a popular comment by Jake Wharton, ActionBar Sherlock is his project, and as he says: "This is the correct way."



来源:https://stackoverflow.com/questions/12101224/how-to-change-sherlock-action-bar-text-color-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!