How to change Sherlock action bar text color progr

2019-08-04 04:04发布

问题:

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