jhall
jhall

Reputation: 77

How to change Sherlock action bar text color programatically?

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.

Upvotes: 1

Views: 4004

Answers (2)

jhall
jhall

Reputation: 77

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.

Upvotes: 3

Sam
Sam

Reputation: 86948

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

Upvotes: 1

Related Questions