Android changes colors using themes

I am trying to provide the user with custom colors in my application. White text on a black background and black text on a white background. I have several layouts with a large number of lists, both standard and custom adapters. People suggested using Themes, but I was not lucky to change the colors of the text in all layouts. Can someone show me the actual layout of a topic that can do this? I can easily change the background colors using myscreen.setBackGroundColor (xx), but when I try to change the text with the theme, it also changes the text using spinner.

+4
source share
2 answers

Use

<item name="android:spinnerStyle">@style/StandardSpinner</item> <item name="android:spinnerItemStyle">@style/StandardSpinnerItem</item> <item name="android:spinnerDropDownItemStyle">@style/StandardSpinnerDropDownItem</item> 

in your topic, this will override the text style.

Your style will look something like this:

 <style name="StandardSpinner" parent="@android:style/Widget.Spinner"> <item name="android:background">@drawable/spinner</item> </style> <style name="StandardSpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem"> <item name="android:textAppearance">@style/GameDisplayText</item> <item name="android:gravity">center_vertical|center_horizontal</item> </style> <style name="StandardSpinnerDropDownItem" parent="@android:style/Widget.DropDownItem.Spinner"> <item name="android:textAppearance">@style/GameDisplayText</item> </style> 
+13
source

Just additional information, to indicate the theme for your application, you need to define it on AndroidManifest.xml

ex.

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/Theme"> 

you must reuse some default style properties so declare the default android theme as the parent theme of your

in /styles.xml values ​​or anywhere your theme file

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme" parent="@android:style/Theme"> <!-- Widget styles --> <item name="android:spinnerStyle">@android:style/Widget.Spinner</item> <item name="android:spinnerDropDownItemStyle">@style/Widget.DropDownItem.Spinner</item> <item name="android:spinnerItemStyle">@android:style/Widget.TextView.SpinnerItem</item> </style> 
0
source

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


All Articles