Changing android search dialog text color - android

I styled my App using a theme as described here.
<style name="MyThemeNameHere" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:textColor">#eee</item>
<style>
It works like a charm in most of the App. The background is pretty dark while the text color is bright and text looks good and is easy to read.
Now in the search dialog that android creates for me the background is white, but the text color picks up my style and gets very bright and thus extremely hard to read. I tried also setting android:background to a dark color - This fixed the problem in the search dialog, but caused all textview, etc to get a dark background rather than transparent.
I want to either set the the color or the background only on the search dialog. How do I do this?

As pointed out by Mark Philip the solution can be found in this question:
Android Styling/Theming of just Search Dialog
Basically it should be styled like so
<style name="master" paret="#android:style/Theme.NoTitleBar">
<item name="android:textColorPrimary">#EEEEEE</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:textColorTertiary">#EEEEEE</item>
</style>
The root cause was that I styled the android:textColor which should never be styled.

Related

How to set background color of exposed dropdown PopupWindow?

I'm using an exposed dropdown from material design components. It's an AutoCompleteTextView within a TextInputLayout which basically acts like a spinner. You give it an adapter and it pops up a PopupWindow on click.
The PopupWindow background is a dark gray. I'd like to change it to white. I've tried this via theming to no avail:
<style name="PopupWindow">
<item name="popupMenuBackground">#color/white</item>
<item name="android:popupBackground">#color/white</item>
<item name="android:windowBackground">#color/white</item>
</style>
I've also tried calling this on the AutoCompleteTextView:
autoCompleteTextView.setDropDownBackgroundResource(R.color.white);
This actually worked. However, if I open the dropdown when the keyboard is open, the background turns dark gray again. It's only when the keyboard is dismissed that the background is white.
Any idea how to solve this? Surely there has to be a theme attribute that I can override to make the PopupWindow background white?
Found the solution thanks to this post: https://medium.com/#rmirabelle/there-is-no-material-design-spinner-for-android-3261b7c77da8
Just override colorSurface in your theme:
<item name="colorSurface">#color/white</item>

2 Spinner with different style in same project

Surfing the web I've found this site which generates Android custom themes. I've used it to create my personal theme: it inherits from Android:Widget.Holo (should be the dark one with white text) and some fancy widget witha a custom color.
Because the theme inherits from Android:Widget.Holo, I have dark background and white text; but in some activity i need the opposite: white background with dark text.
When it comes to change the text color of most item i can do it easily using android:textColor="#android:color/black", but when i try to use it on spinner item it does nothing.
I've tried to create a new style only for spinner items, but i canno't apply it...
This is the first style generated (white text on black background):
<style name="SpinnerAppTheme" parent="android:Widget.Holo.Spinner">
<item name="android:background">#drawable/apptheme_spinner_background_holo_dark</item>
<item name="android:dropDownSelector">#drawable/apptheme_list_selector_holo_dark</item>
</style>
And this is the second I've generated (the opposite, back text on white background):
<style name="SpinnerDarkTextAppTheme" parent="android:Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/apptheme_spinner_background_holo_light</item>
<item name="android:dropDownSelector">#drawable/apptheme_list_selector_holo_light</item>
<item name="android:textColor">#android:color/black</item>
</style>
But when I use style="#style/SpinnerDarkTextAppTheme nothing happens.
How can I do to have 2 different styles (obviously working at the same time) for my spinners?
SOLVED using this piece of code.
You can create two themes in the XML and switch between them before you set the content view:
https://stackoverflow.com/a/6390025/2219600
Another approach:
https://stackoverflow.com/a/16101936/2219600

TextView style in dialog, can not see text in froyo but can see in ics

I have a dialog box that I create to display messages in android. It basically contains a text view in a scrollview like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/about_msg"
android:text="#string/about_msg"
android:autoLink="web"
android:padding="10dip"
style="#style/DialogTextSmall" />
</ScrollView>
As you can see I have applied a style to TextView the style looks like this
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The application theme set is like this
<style name="AppTheme" parent="android:Theme.Light">
The Problem:
On ICS api-15 it shows fine black text on white background of TextView.
The problem is When I show dialogbox in Froyo its the text does'nt seem to show even though it seems to have taken space - My guess is the color of text is same as background (greyish black)
I know I can quick fix by hard-coding black background and white text, but Is it not possible to have the default colors of platform for the text color and background of the TextView to appear, without me having to hardcode them ?
You can inherit a parent style and then only change the values you want to change. Try changing your XML to this:
<style name="DialogTextSmall" parent="#android:style/Widget.TextView>
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The list of styles you can inherit can be found in the AOSP source on Github here.
EIDT:
By default text views have black text and transparent background, so you will need to set one or the other if the background behind the text view (which, again, is transparent) is black.
Inheritance from Textview style did not really help. It is a little quirky problem and here is one way to do it
http://blog.andromo.com/2011/fixing-text-colours-on-an-alertdialog-when-using-theme-light/
In my case I did it another way
Solved it for theme I inherited it from default android theme
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.AppTheme" parent="#android:style/Theme.Light"/>
and
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
<item name="android:textColor">#android:color/white</item>
</style>
This way for all platforms , froyo, gingerbread and above, the dialog boxes are black and text is white on them

Dialogs using ActionBarSherlock/HoloEverywhere Light

I'm using Christophe Versiuex's HoloEverywhere library project and the Theme.HoloEverywhereLight.Sherlock theme.
The system dialog boxes - copy all text, date picker dialog, etc - all have white text as the window title rather than the light blue. You can see this if you run the demo.
I've tried styling them using android:windowTitleStyle but with no luck. Is anyone using this and found a workaround?
Thanks.
The title text is hard to change. You can change the background color for the title so it becomes readable, and leave everything else in the light theme:
<style name="Theme.MyTheme"
parent="Theme.HoloEverywhereLight.DarkActionBar.Sherlock">
<item name="android:alertDialogStyle">#style/AlertDialogHoloMix</item>
</style>
<style name="AlertDialogHoloMix"
parent="AlertDialogHoloLight">
<item name="android:topDark">#drawable/dialog_top_holo_dark</item>
</style>
I tested this on Gingerbread and ICS.

styling ActionbarSherlock: textColor of the action-items

I was changing the background of the Actionbar in my App and to make text readable again I have to change the color of the text. I was successful with title/subtitle and the tab-texts, but I am struggling with the text of the action-items - they stay white no matter what I tried . Anyone has a hint on how to do that?
Also the overflow-icon is white which does not look too good on the wooden background - is that an extremely good reason to use the stuff below? I am not really sure what's the reason to not do it, but as I do not have a big device-test-park I better want to be sure ;-)
<!-- the following can be used to style the overflow menu button
only do this if you have an *extremely* good reason to!! -->
<!--<style name="MyOverflowButton" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">#drawable/ic_menu_view</item>
<item name="android:background">#drawable/action_button_background</item>
</style>-->
I also struggled with this, but the solution to changing action item text color was:
<style name="My.Theme" parent="Theme.Sherlock.Light">
<item name="android:actionMenuTextColor">#android:color/white</item>
</style>
The key here was to use this attribute in the general theme, not in the actionbar style.
Try starting with android:theme="#style/Theme.Sherlock.Light" in your Manifest and then changing your styles. The light theme features dark action items. Or just look through the light theme to find out how to change them.

Categories

Resources