Change holo spinner text colour - android

I have a spinner in a Holo theme dialog and am trying to change the text colour because it is very hard to read:
I have looked at android styles.xml, as well as many other answers, and believe that I am setting the custom style correctly; but it's just not getting picked up.
This is an extract from the dialog layout file where the spinner lives:
<Spinner
android:id="#+id/spn_Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/dose_type_options"
style="#style/DialogSpinner" />
And these are the relevant entries in styles.xml in the values-v14 folder:
<style name="DialogSpinner" parent="#android:style/Widget.Holo.Spinner">
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MySpinnerItem" parent="android:Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearanceSpinnerItem</item>
</style>
<style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
</style>
The dialog itself is forced to the Holo dark theme by using:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
</style>
Can anyone identify why the spinner text isn't white?
I have looked at other solutions, which suggest changing the colour in code, but this app supports 2.3.* upwards, so for those non-holo versions black text is fine, hence trying to do it by styles.
Thanks
Updated using answer from Woda below
The text colour of the initial value of the spinner is now white, which goes a long way to highlighting that there is a spinner there for the user:
But the text colour of the selectable items is still black. I guess it's not a massive deal, at least the existence of the spinner has been affirmed by getting the initial text changed to white. But I would be interested to know why the items are still black, and how to change them to white.

Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:
theme.xml:
<style name="exampleTheme" parent="android:Theme.Holo.Light">
<item name="android:spinnerItemStyle">#style/SpinnerItem_example</item>
...
</style>
style.xml:
<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#000000</item>
</style>
Update:
Taking a deeper look into the styles.xml brought me this:
<style name="Widget.DropDownItem.Spinner">
<item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>
<style name="Widget.DropDownItem">
<item name="android:textAppearance">#style/TextAppearance.Widget.DropDownItem</item>
<item name="android:paddingStart">#dimen/dropdownitem_text_padding_left</item>
<item name="android:paddingEnd">#dimen/dropdownitem_text_padding_right</item>
<item name="android:gravity">center_vertical</item>
</style>
So you probably need to customize the Widget.DropDownItem and accept it in your theme.
...
<item name="dropDownItemStyle">#android:style/Widget.DropDownItem</item>
...
For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.
themes.xml
styles.xml

I fixed it by calling
mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());
Hope this helps someone ;)

You can access the internal TextView in code without changing any styles. This is how I handled enabling and disabling Spinners
The .getSelectedView() did not work for me. So I tricked the Spinner to "show" being disabled.
You will need to define your own colors for the "disabled" look.
For Example:
R.color.blue_text //means enabled
R.color.gray_text //means disabled
So to disable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
mySpinner.setEnabled(false);
mySpinner.setFocusable(false);
To enable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
mySpinner.setEnabled(true);
mySpinner.setFocusable(true);
The getChildAt(0) function allows you to access the first item in the spinner, which is what you show on the screen as a TextView.
You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.

Related

Overwrite default list view highlighted color in AppCompat theme

My application's main theme inherits from Theme.AppCompat, and I've created a selector that allows for the Ripple effect to take place when you press and focus a button on Lollipop.
However, when I go back to a 4.0 device, it defaults back to an ugly blue color when I focus a list view item. I've looked everywhere for the trait that defines this color hoping to override it without any luck - any idea how I can do this?
Add this to your theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:listViewStyle">#style/ListViewAppTheme</item>
<item name="android:listViewWhiteStyle">#style/ListViewAppTheme.White</item>
</style>
<style name="ListViewAppTheme" parent="Base.Widget.AppCompat.ListView">
<item name="android:listSelector">#drawable/abc_list_selector_dark</item>
<item name="android:divider">#drawable/ab_divider_light</item>
<item name="android:dividerHeight">1px</item>
</style>
<style name="ListViewAppTheme.White" parent="Base.Widget.AppCompat.ListView.White">
<item name="android:listSelector">#drawable/abc_list_selector_dark</item>
<item name="android:divider">#drawable/ab_divider_light</item>
<item name="android:dividerHeight">1px</item>
</style>
Change #drawable/abc_list_selector_dark to whatever selector you want to use. As an added bonus, I added how to change the listview's divider and its height.
Unfortunately doesn't seem to be working. The list views still seem to
be getting that disgusting default blue color from SOMEWHERE, although
I can't figure out where.
I used to feel like you, both on the disgusting and the angry somewhere part. However I managed to get rid of it.
If I remember well, the culprit should be android:listChoiceBackgroundIndicator. Try this:
<style name="MainTheme" parent="Theme.AppCompat">
<item name="android:listChoiceBackgroundIndicator">#drawable/my_selector</item>
<item name="listChoiceBackgroundIndicator">#drawable/my_selector</item>
</style>

ListPreference item row text color

I'm searching for this for a couple of days but cannot find an answer that I can manage to get working for now.
I would like to allow the user to select in a list different themes for the whole application for day/night purposes.
The issue is that I can't find a way to change the colors of the text for a ListPreference row Item textColor. Some solutions I've found are talking about using the attribute
<item name="android:textColorPrimary">#color/red_color</item>
in the style in order to set that text. However this has no effect during my tests using API 11. The results I obtained after many attempts is almost always the same: When setting different styles for the application I can change the title color for the ListPreference but not the row items text color:
Here is the screenshot :
These are the styles I am using:
<!-- Application theme. -->
<style name="AppTheme.Daylight" parent="AppBaseTheme">
<item name="android:background">#color/white</item>
<item name="android:panelBackground">#color/gray</item>
<item name="android:textColor">#color/black</item>
</style>
<style name="AppTheme.Dusk" parent="AppBaseTheme">
<item name="android:background">#color/black</item>
<item name="android:panelBackground">#color/gray</item>
<item name="android:textColor">#color/salmon</item>
</style>
<style name="AppTheme.Night" parent="AppBaseTheme">
<item name="android:background">#color/black</item>
<item name="android:panelBackground">#color/gray</item>
<item name="android:textColor">#color/red</item>
</style>
This is the display preference fragment xml file
<PreferenceCategory
android:title="#string/preference_display_settings"
android:key="display_preferences">
<ListPreference
android:key="display_mode"
android:title="#string/preference_display_settings"
android:entries="#array/preference_display_mode_available"
android:entryValues="#array/preference_display_mode_values" />
</PreferenceCategory>
Basically the question I'm asking is:
- How to change the color of the entries text color in a ListPreference?
Some articles on the web are explaining how to create custom ListPreference view such as this article Custom ListPreference
Is creating a curstom view the only way to change the text color or is there an attribute or property that I am missing for the ListPreference View ?
Lots of thanks in advance, I'm a newbie in Android and just got out of the Coursera MOOC to create this open source application.
You can change the value for the attribute android:textColorAlertDialogListItem like below in your theme definition.
<item name="android:textColorAlertDialogListItem">#color/white</item>
That worked for me. Good luck!!

Light.DarkActionBar menu item text colour unchangeable?

The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black.
My main theme contains
<item name="android:panelBackground">#drawable/menu_hardkey_panel</item>
...Where #drawable/menu_hardkey_panel is a dark coloured 9patch.
The resulting appearance of the menu popup is...
I'm unable to determine why this is happening, or how to manually change the colour of the text. In my main theme, I've tried all of the following...
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">#style/MyMenuTextAppearance.Large</item>
<item name="android:textAppearanceSmallPopupMenu">#style/MyMenuTextAppearance.Small</item>
I've even tried
<item name="android:actionBarWidgetTheme">#style/Theme.MyApp.Dark</item>
...Where Theme.MyApp.Dark is...
<style name="Theme.MyApp.Dark" parent="#style/Theme.Sherlock">
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
</style>
None have let me change the text to white. If I make my base theme inherit from Theme.Sherlock, the problem is solved and the text is white, but unfortunately that's not an option.
Not entirely sure about this, but I believe the pop-up menu uses the same styling as the overflow menu. In which case you'd just do something like this.
<item name="android:itemTextAppearance">#style/your_new_text_appearance</item>
<style name="your_new_text_appearance">
<item name="android:textColor">#android:color/white</item>
</style>
Giving it a chance: there is a text appearance called actionMenuTextAppearance. Have you tried that?
Update: I did some more digging and I believe that this file is the layout And there they refer to textAppearanceListItemSmall and textAppearanceSmall. However, it takes this value from a special theme which is specified as following in Theme.Holo.Light
<item name="panelMenuListTheme">#android:style/Theme.Holo.Light.CompactMenu</item>
And like this in Theme.Holo:
<item name="panelMenuListTheme">#android:style/Theme.Holo.CompactMenu</item>
The problems comes from the fact that the parent of Sherlock.__Theme.DarkActionBar is Theme.Sherlock.Light. This is not valid for the dark action bar. Taking the line from Theme.Holo should do the trick.
In my research I haven't found a way to change the text color, but you can at least handle hardkey menus gracefully.
This link provided me with a passable solution to the problem:
https://github.com/jgilfelt/android-actionbarstylegenerator/issues/30
Commenting out the "android:panelBackground" item from my generated theme allowed the text to at least be visible on hardkey menus, even if it doesn't perfectly match the theme.
You could also try replacing the "menu_hardkey_panel_whatever.9.png" drawable with something that will work for your theme and the black text.
For me this solves the problem, try this instead:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<item name="actionBarWidgetTheme">#null</item>
<item name="android:actionBarWidgetTheme">#null</item>
...
</style>
I found the solution, use:
getSupportActionBarContext()
e.g.
ArrayAdapter<CharSequence> list =
ArrayAdapter.createFromResource(getSupportActionBarContext(), R.array.navigation, layout.simple_spinner_item);
list.setDropDownViewResource(layout.simple_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
I think that due to the fact that Theme.Sherlock.Light.DarkActionBar don't style its contents right is due to the actionWidgetTheme attribute is used with a ContextThemeWrapper for inflating the action bar views (Jake Wharton's own words), thus something like the following (not tested) will be needed to fulfill your needs, though breaking your need of not using Theme.Sherlock as parent in one way:
<style name="MyColorTheme" parent="Theme.Sherlock">
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="YourMainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/MyColorTheme</item>
<item name="actionMenuTextAppearance">#style/MyColorTheme</item>
</style>
Might work or not work. That's the question :)

Custom theme breaks spinner apperance

I am currently working on dynamically changing themes with a settings option. The themes are very simple and only change background color. After changing theme, the spinners do not look right see image http://imageshack.us/photo/my-images/600/baddropdown.png/
I solved the first issue (the spinner itself) with a custom spinner item that sets the background transparent
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:ellipsize="marquee"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:singleLine="true"
style="?android:attr/spinnerItemStyle"
android:background="#android:color/transparent"
android:id="#android:id/text1" />
I tried the same with a custom spinner_dropdown_item but it did not work. Any ideas what I can try to get the default spinner appearance would be greatly appreciated.
EDIT: I was able to change the spinner_dropdown_item background http://imageshack.us/photo/my-images/10/halfbaddropdown.png/ but the drop down prompt background and separators are the application backgrounds color but I want the default appearance.
NOTE: removed an image link so I could post the newest.
EDIT: Issue has been resolved, acctually ended up being a simple fix. Had to change my custom theme which was
<style name="grey" parent="#android:style/Theme.Light">
<item name="android:background">#EEE9E9</item>
</style>
in styles.xml to
<style name="grey" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/converter_grey</item>
</style>
and define the color in colors.xml
Issue has been resolved, acctually ended up being a simple fix. Had to change my custom theme which was
<style name="grey" parent="#android:style/Theme.Light">
<item name="android:background">#EEE9E9</item>
</style>
in styles.xml to
<style name="grey" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/converter_grey</item>
</style>
and define the color in colors.xml

Setting Application theme textColor to white causes Context Menu item text to be white (invisible)

Ok, this is driving me bonkers. To skin my app, I set the following in my theme:
<item name="android:textColor">#FFFFFF</item>
All the text in the app turns white, unless I manually override it in the layout xmls. Great, yay, easy peasy. EXCEPT that the text in my menu options for context menus (off of lists and such) have also decided to become white.
This is not so great, since it is hard to read white on white. I have tried a variety of solutions, including searching for how to change the text color of a context menu (no dice)and creating a textAppearance item in my theme. The last solution didn't change all the textfields in my app, which was frustrating.
So, any suggestions? Hopefully my dilema is clear.
In your styles.xml try overriding the textViewStyle instead of just ALL textColor attributes:
<style name="Theme.Blundell.Light" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/background_light</item>
<item name="android:textViewStyle">#style/Widget.TextView.Black</item>
</style>
<style name="Widget.TextView.Black" parent="#android:style/Widget.TextView">
<item name="android:textColor">#000000</item>
</style>
You could even take it one further and just override the color for a certain view, like buttons:
<style name="Widget.Holo.Button" parent="#android:style/Widget.Holo.Button">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="Theme.Blundell" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:colorBackground">#android:color/transparent</item>
<item name="android:buttonStyle">#style/Widget.Holo.Button</item>
</style>
If your inspired to do any more theming check out the Android source it's the best place to realise what you can and can't do!:
https://github.com/android/platform_frameworks_base/tree/master/core/res/res/values
Use this:
parent="Theme.AppCompat.Light.DarkActionBar"

Categories

Resources