I am trying to modify the text color of the title of the ActionBarSupport. I have used ActionBarStyleGenererator to create a theme with the correct colors and it works well.
While using the light theme, I would like to change the color of the heading to white (in the genererator I cannot set the text color(. For a number of reasons I cannot use the dark actionbar theme. I am so close, just have to get the title to white ;-)
What I am doing wrong here?
<style name="ActionBar.Transparent.MyApp" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="background">@drawable/ab_transparent_myapp</item>
<item name="progressBarStyle">@style/ProgressBar.MyApp</item>
<item name="titleTextStyle">@style/MyApp.TitleTextStyle</item>
</style>
<style name="MyApp.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">#ffffff</item>
</style>
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.
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.
Go to the app > res > values > themes > themes. xml file and add the following line inside the <resources> tag. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar.
The below code worked for me. I hope it will help you tooo.
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">@style/ActionBarCompat</item>
</style>
<style name="ActionBarCompat" parent="@style/Widget.AppCompat.Base.ActionBar">
<item name="titleTextStyle">@style/titleStyle</item>
</style>
<style name="titleStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
Embarrassing. I was not paying attention to the values-v14/-folder (which overrides the vales/) ActionBarStyleGenererator created. Using the android-prefix on the styles in values-v14 it worked:
<item name="android:titleTextStyle">@style/titleTextStyle</item>
Found at Overflow styling
I've been trying to keep the ActionBar title text color through orientation changes without much luck until I got a clue from the above site. I applied the Spannable to to the title. Here's what i do when setting up my ActionBar:
Spannable actionBarTitle = new SpannableString("Action Bar Title");
actionBarTitle.setSpan(
new ForegroundColorSpan(Color.WHITE),
0,
actionBarTitle.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mActionBar.setTitle(actionBarTitle);
This needs to be executed on orientation change. I call it from onCreate()...don't know if it works in onConfigurationChange().
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