Actionbar Compatibility change name textColor

I am trying to change the text color of an ActionBarSupport header. I used ActionBarStyleGenererator to create a theme with the right colors, and it works well.

When using a light theme, I would like to change the title color to white (in the generator I canโ€™t set the color of the text (for a number of reasons I canโ€™t use the dark theme in action). Iโ€™m so close, I just need to get the name to white ;-)

What am I 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> 
+6
source share
4 answers

I am ashamed. I did not pay attention to the values โ€‹โ€‹of -v14 / -folder (which overrides vales /) of the ActionBarStyleGenererator. Using the android prefix in styles in values-v14, it worked:

  <item name="android:titleTextStyle">@style/titleTextStyle</item> 
+5
source

The following code worked for me. Hope this helps you do this.

 <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> 
+14
source

Overflow Style Found

I am trying to keep the text color of the ActionBar header through orientation changes without much luck until I get the key to the above site. I applied Spannable to the title. Here is 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 must be done when changing orientation. I call it from onCreate () ... I donโ€™t know if it works in onConfigurationChange ().

+3
source

@TNR is correct, however you should double check if your xml layout file has changed the android:theme attribute with a different style.

This usually happens if you have created layout files.

0
source

Source: https://habr.com/ru/post/959484/


All Articles