How can I create a global theme with different text colors for TextView and Spinner?

I am writing an application that needs the following two things:

  • The general text (in TextView s) should be the same color (white, in this case, a dark background)
  • Spinner text should be in a different color (black, since white is too hard to read)

I used the theme applied at the application level in the manifest to execute the first element above.

 <resources> <style name="GlobalTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <item name="android:textColor">#FFFFFF</item> </style> </resources> 

Worked great. In addition, he also makes the text on the spinner white, which is difficult to read.

OK, so I want the color video to still be black, but everything else is white.

I found this question that showed how to set the color of Spinner text, and it works, but only when I also do not set the global textColor.

So the following does not work:

 <resources> <style name="GlobalTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <item name="android:textColor">#FFFFFF</item> <item name="android:spinnerItemStyle">@style/GlobalThemeSpinnerItem</item> </style> <style name="GlobalThemeSpinnerItem" parent="android:Widget.TextView.SpinnerItem"> <item name="android:textAppearance">@style/GlobalThemeTextAppearanceSpinnerItem</item> </style> <style name="GlobalThemeTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem"> <item name="android:textColor">#000000</item> </style> </resources> 

I guess I was hoping it would be like CSS and everything would be cascading down (i.e. "all text should be white, except that it is in the spinner"). If I delete the android:textColor in the main theme, the colored color trick works fine.

It seems that SpinnerItem comes from TextView , so I tried to find a split like textViewStyle similar to a split spinnerItemStyle , but no luck.

Unlike most people who ask about it, I want to save it as much as possible in XML. Does anyone know what I'm doing wrong?

+7
source share
1 answer

Try the following:

 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="GlobalTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <item name="android:spinnerItemStyle">@style/GlobalThemeSpinnerItem</item> <item name="android:textViewStyle">@style/GlobalThemeTextViewItem</item> </style> <style name="GlobalThemeTextViewItem" parent="android:Widget.TextView"> <item name="android:textAppearance">@style/GlobalThemeTextAppearanceTextViewItem</item> </style> <style name="GlobalThemeTextAppearanceTextViewItem" parent="android:TextAppearance.Widget.TextView"> <item name="android:textColor">#FFFFFF</item> </style> <style name="GlobalThemeSpinnerItem" parent="android:Widget.TextView.SpinnerItem"> <item name="android:textAppearance">@style/GlobalThemeTextAppearanceSpinnerItem</item> </style> <style name="GlobalThemeTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem"> <item name="android:textColor">#000000</item> </style> 

This will make the text in the text TextViews white and the text in black Spinners black.

+1
source

All Articles