0

I have an app which is using a black background. I've been developing and testing it on Lollipop, yet minSDK is 19. When I use a KitKat device (or emulator), I run into a problem with the white text I see on my Lollipop device - it is black and thus invisible.

I define the text color like this:

<TextView
    android:id="@+id/list_header_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dp"
    android:text="27.02.2016"
    android:textColor="@color/text_primary"
    android:textSize="16dp"/>

Then, in (all) my styles.xml I have the following theme defined:

 <style name="AppTheme.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/text_primary</item>
    <item name="android:background">@color/colorPrimary</item>
   </style>

In colors.xml, text_primary is defined like this:

<color name="text_primary">#FFFFFF</color>

Once again, on Lollipop I can see the text in pure perfect white, yet on KitKat it appears black. Where did I go wrong? In my opinion, since the TextView textcolor is defined explicitly to be text_primary it should work on across all SDK versions?!

Maverick283
  • 1,284
  • 3
  • 16
  • 33
  • http://stackoverflow.com/questions/26852108/how-do-you-set-the-title-color-for-the-new-toolbar – zgc7009 May 12 '16 at 16:37
  • @zgc7009 I see how this relates to my question, yet it doesn't solve it. Or at least I can not gasp a solution from it. If it is somewhere hidden in that thread, would you mind pointing it out to dummies like me? :) – Maverick283 May 12 '16 at 16:50
  • You may need to look into the type of theme that you have. I think you will need to utilize some sort of Theme.AppCompat.*. Not that I am 100% on this as I haven't messed much with styling in a little while, but I am pretty sure that the major overhaul of the design patterns in Lollipop would require some sort of AppCompat. This link may provide a bit more (again not sure this is a solution, more of a suggestion of something to look at) http://stackoverflow.com/questions/20653305/full-screen-theme-for-appcompat – zgc7009 May 12 '16 at 16:55
  • 1
    Thank you man, you are genius... If you like go ahead an post that as an answer. You can include a code suggestion as follows: "change ` – Maverick283 May 12 '16 at 17:02
  • No sweat, I just made some recommendations. Go ahead and post the change you made to your code to get it up and running again as a more specific answer. Hopefully it will help some of those in the future :) Happy coding. – zgc7009 May 12 '16 at 17:04

1 Answers1

0

Thanks to @zgc7009 this was resolved rather quickly:

As he was suggesting, the major overhaul of the design patterns in Lollipop requires some sort of AppCompat. Based on that and with a little bit of luck the following additions to the ../values-v19/styles.xml file made the text appear white in KitKat again:

 <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/text_primary</item>
</style>

Notice how I added a AppCompat parent to my custom style. I gotta be honest, I'm not exactly sure why it affects the color of the TextViews, if anyone knows feel free to edit or comment. Hope this helps a couple guys in the future.

Maverick283
  • 1,284
  • 3
  • 16
  • 33
  • 1
    The AppCompat parent theme incorporates compatibility styles that allows attributes to work across versions :) From this link http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html `"When you set these attributes, AppCompat automatically propagates their values to the framework attributes on API 21+.` – zgc7009 May 12 '16 at 17:19