I'm having trouble changing androids action bar title color programmatically for v11 and up. I can get it done in xml but need to change it dynamically in code. How should I go about this? Thanks in advance.
xml in values folder this will change your action bar color.. Replace #666666 with your selected color code for title background color and replace #000000 for your title text color.
Go to the app > res > values > themes > themes.
This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
The ActionBar
title ID is hidden, or in other words, it's internal and accessing it can't be done typically. You can reference it using Resources.getIdentifier
then View.findViewById
though.
Grab the ID for the action_bar_title
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
Now you can use the ID with a TextView
TextView abTitle = (TextView) findViewById(titleId); abTitle.setTextColor(colorId);
You can use a SpannableString and ForegroundColorSpan to set the colour of the title
Spannable text = new SpannableString(actionBar.getTitle()); text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); actionBar.setTitle(text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With