views:

46

answers:

2

I'm changing the theme of an activity in onCreate using setTheme (I'm doing that even before calling super.onCreate(), as this is supposed to be more reliable).

It does work in the sense that it changes the background and foreground colors. However, my layout has a few elements that use styles like textAppearanceLarge. Now Android's textAppearanceLarge internally uses the textPrimaryColor - which is still unchanged by my theme.

I tried to override the primary text color in my theme, but that doesn't seem to work.

Here is the crucial part of the theme:

<style name="Theme.MyApp.White">
   <item name="android:background">@android:color/white</item>
   <item name="android:textColor">#000000</item>
</style>

The background appears white, plain TextViews appear black... but TextViews using textAppearanceLarge are white, and as such invisible (white on white).

I tried things like this:

   <item name="android:ColorPrimary">#000000</item>
   <item name="android:textColorPrimary">#000000</item>
   <item name="android:attr/textColorPrimary">#000000</item>

But none of those do anything. What's the magic trick?

+1  A: 

Hi Mike,

Just as a workaround, Instead of using textAppearanceLarge in the layout, (if you're using xml to build the layout), define your own textAppearanceLarge style in the styles.xml that emulates the android default one except you can change the color to white.

xml layout:

<!-- example textview -->
<TextView style="@style/large" android:text="text goes here"></TextView>

then in the styles.xml

<style name="large">
    <item name="android:textColor">@android:color/white</item>
    <!-- other necessary items here like font etc.-->
</style>
zsniper
Thanks snipe! To elaborate: I'm trying to add themes to my app that you can switch inbetween, so basically I have one style per theme that is supposed to define the entire look - if the user chooses the "white" theme, everything will be black on white, etc. I don't know how I would set that up if I had a separate style for "large".
EboMike
A: 

Turns out I was barking up the wrong tree. Overriding the colors and everything worked just fine. However, by defining android:background in my theme, everything just completely messed up, and all text appeared white, despite me overriding all colors (including textColorPrimary). Omitting android:background did the trick.

EboMike
ah. glad that worked out for you! ;)
zsniper
I still appreciate your answer (although you were more talking about styles, I was thinking about themes). I'm slowly starting to get it, although it's still a bit shaky.
EboMike