I am doing a few lessons and I tried to add textColor. This works great using the attribute in each widget - is it an xml layout or a style attribute. But I was wondering if it is possible to define a global textColor, as far as I can see, it is not.
I found a solution on these pages:
http://www.therealjoshua.com/2012/01/styling-android-with-defaults/
http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/
In my little program, I used EditText, RadioButton and Button. If I set TextAppearance for each Singel widget with a style block with the parent @android: TextAppearance, the widgets lost other attributes. So I searched style.xml and theme.xml and found a very short solution:
<resources> <style name="MyTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:editTextColor">@android:color/white</item> <item name="android:textColorPrimaryDisableOnly">#FFFFFF</item> <item name="android:color/primary_text_light">#FFFFFF</item> </style> </resources>
Although theme.xml uses a predefined color
<style name="TextAppearance.Widget.Button" parent="TextAppearance.Small.Inverse"> <item name="android:textColor">@android:color/primary_text_light_nodisable</item> </style>
My first question is: is there a way to rewrite the value of @android: color / primary_text_light_nodisable, as was done with other attributes?
In fact, I think I myself solved this problem:
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="MyTheme" parent="android:Theme.Light"> <item name="android:textAppearance">@style/MyTextAppearance</item> <item name="android:textAppearanceButton">@style/MyTextAppearanceButton</item> <item name="android:editTextStyle">@style/MyEditTextStyle</item> <item name="android:radioButtonStyle">@style/MyRadioButtonStyle</item> </style> <style name="MyTextAppearance" parent="@android:style/TextAppearance"> <item name="android:textColor">@android:color/white</item> </style> <style name="MyTextAppearanceButton" parent="@android:style/TextAppearance.Widget.Button"> <item name="android:textColor">@android:color/white</item> </style> <style name="MyEditTextStyle" parent="@android:style/Widget.EditText"> <item name="android:textColor">@android:color/white</item> </style> <style name="MyRadioButtonStyle" parent="@android:style/Widget.CompoundButton.RadioButton"> <item name="android:textColor">@android:color/white</item> </style> </resources>
So my second question is: is this the right way or is there a short way to change globaly text color?
Althoug I think that defining all this in xml is the purest method, I wanted to know if you suggest manipulating this with class methods?
Sorry, I'm pretty new to Java and Android programming and thank you for your help!