How can I style the title of the Spinner dialog by xml? - android

In my current implementation, I have modified the whole style of my application...
I successfully modified the Spinner style, so I was able to change the RadioButton look and feel:
I am now working on the title, but seems really hard to style.
I would like to change, for instance the title text color (and optionally removing the triangle)
I know I could do that by extending Spinner or Dialog, but I have to do achieve that by playing with xml.
Here is my current code that succesfully modified other dialog properties:
<style name="Theme.HoloEverywhereDark.Sherlock" parent="Theme.Sherlock">
<item name="android:spinnerStyle">#style/SpinnerDark</item>
<item name="android:spinnerItemStyle">#style/SpinnerItemDark</item>
<item name="android:spinnerDropDownItemStyle">#style/DropDownItemDark</item>
</style>

To change the triangle, you could use the second answer here: How to create android spinner without down triangle on the right side of the widget
I haven't yet figured out how to style the main text, but you may just be able to apply normal text field formatting to it via the Spinner in xml (textColor, etc).

Related

Can I change color of Android DatePicker (Mode - Spinner) selected item?

I am developing an application where I need to show a dialog with a DatePicker in it. Now my designs are such that the DatePicker should be Spinner mode as was prior to Material Design. I want it to look something like this -
I'm trying to make my custom view of the dialog and then use datepicker spinner in android but then I am not able to change the color of the selected number to Red. How to change the color of the numbers selected in between to red as shown in the image?
Can someone help me on this?
The color depends on the theme set on the Dialog used to inflate the layout.
Set up a basic theme like this:
<style name="PickerDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/error_red</item>
</style>
where the colorAccent attribute applies the color you want to your DatePicker

What property controls Spinner dropdown background?

I have a custom theme created with this generator. It has a custom style for Spinners which I don't like. I want to change the background drawable but I can't seem to figure out which property controls this.
This is what the themed version looks like
And here is what it will look like when using the Holo.Light theme.
Notice the dark gray lines around the dropdown list in the first (themed) image. This is what I want to get rid of. What property controls this? I want them to match the default.
Also, what controls the vertical aligment of the dropdown list? As you can see, it is overlapping with the Spinner in the first image (the line under it isn't visible as it is in the second image).
The attribute you want is android:popupBackground on the Spinner element.
If you look closely, the holo popup also overlaps the spinner some, but there is a bunch of padding for the drop shadow, so it looks good.
However, you can use android:dropDownVerticalOffset on the Spinner element to adjust it.
We came across the same issue. It has to do with the Android Holo theme generator.
Here are the lines that you should remove from your Theme.xml file...
<item name="android:spinnerStyle">#style/SpinnerCustom</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemCustom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
...by removing these, we now have the standard Holo.Light theme on the spinner dropdowns.
You need to change the parent of spinnertheme to android:Widget.Holo.Light.Spinner
<style name="SpinnerTHEME" parent="android:Widget.Holo.Light.Spinner">
<style name="spinner_style" parent="android:Widget.Holo.Light.Spinner">
<item name="android:paddingLeft">#dimen/ten_dp</item>
<item name="android:paddingRight">#dimen/ten_dp</item>
</style>

Change spinner indicator drawable

In 4.x devices, the drawable which indicates that this is a spinner and should be clicked is barely visible; it is using spinner_ab_default_holo_light.9.png. How can I make it use spinner_ab_default_holo_dark.9.png, or any other drawable of my choice?
The spinner is in a dialog. The app uses ActionbarSherlock 4.3.1 for Android 2.2.3 upwards compatibility. The app implements Android Action Bar Style Generator to create a Sherlock.Light.DarkActionBar theme. I am using a Values and a Values-v14 to manage the styles. This dialog attaches a specific style:
new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.FibroDialog))
which, in Values-v14, has a parent theme to make sure the dialog background is dark:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
</style>
Things I have tried:
In the theme generated by Android Action Bar Style Generator I added
<item name="android:spinnerItemStyle">#style/MySpinnerItemStyle</item>
and then added
<style name="MySpinnerItemStyle" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
<item name="android:background">#drawable/spinner_background_ab_fibromapp</item>
</style>
which resulted in the drawable I actually want becoming the background of the item, not the spinner.
In the xml for the spinner, I tried
android:dropDownSelector="#drawable/spinner_ab_default_fibromapp"
which gives the same result as above, and
android:popupBackground="#drawable/spinner_ab_default_fibromapp"
which replaces the background of each spinner item with the drawable.
As a last resort, I made my own spinner_ab_default_holo_dark and spinner_ab_default_holo_light 9-patches; and they didn't show up at all.
How can I access that spinner drawable and change it to whatever graphic I want?
Although i'm new at this, i've also spent far too many hours looking for a similar answer. It seems the only solution is to create a style which is an exact copy of the system's spinner style and edit that which you which to change. It's troublesome, boring and not really practical, but if it must be done, it must be done... Due to time constraints, I ended up changing my layout a bit so that the standard spinner wouldn't look too bad.

Android Styling/Theming of just Search Dialog

tl;dr: White text style in app theme being picked up by search dialog, making search text invisible.
I'm struggling mightily with what seems like a trivial issue.
My app is using a dark background, and I've tweaked the text color to be brighter than the standard gray using #EEEEEE.
I've implemented a Search Dialog (pre-Honeycomb) and it works well, but the text in the search dialog picks up the same #EEEEEE so it is essentially invisible. Even the context menu displayed when I long press the search text picks up #EEEEEE, so the text there is invisible as well.
I'm tearing my hair out, and I'm running out of hair.
Style:
<style name="master" paret="#android:style/Theme.NoTitleBar">
<item name="android:textColor">#EEEEEE</item>
<item name="android:windowNoTitle">true</item>
</style>
Manifest:
<application android:icon="#drawable/icon"
android:label="#string/app_label"
android:theme="#style/master"
android:hardwareAccelerated="true"
android:debuggable="true">
The attribute android:textColor is not meant to be used inside theme styles, it is primarily useful in widget and text appearance styles.
If you want to change the general text colors through a theme, use instead the android:textColor* family of attributes. There are quite a few of them, and different Views use them differently, so it takes a bit of experimentation (or careful studying of the Android source code) to to get it all right. The android.R.attr documentation lists them all. Look for the attributes that begin with textColor....
To get you started, try this theme, it will behave better by not affecting the Search Dialog colors at all, which seems to be what you want. By the way, you don't need to set android:windowNoTitle to true in your theme as your parent theme does that already:
<style name="master" parent="#android:style/Theme.NoTitleBar">
<item name="android:textColorPrimary">#EEEEEE</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:textColorTertiary">#EEEEEE</item>
</style>
I got into the same problem as you. I've looked around for a solution but it seems that you just can't change the textColor of a dialog. My solution was creating a custom dialog based on this tutorial: http://blog.androgames.net/10/custom-android-dialog/
I extended this a lot based on the Android source code, always using the same method names etc to make it a bit easier.
It is not ideal, but as far as I know it's the best option...
EDIT: for your problem there might be a simpler solution: don't put the textColor into the theme, but put it in a style. I don't know how you're styling your app but I'm usually creating a "master-style" which all the others inherit from (direct or indirect). You could then put the textColor in there so all your standard dialogs will still have the standard textColor.

Adding style to ActionBar drop down spinner makes it not a drop down

I'm using this tutorial:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
I set a drop down list theme like this
<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar">
<item name="android:textColor">#ffffff</item>
</style>
and now pressing the spinner causes it to show up centered on the screen instead of as a drop down. Has anyone run into this? I'm using exactly what they said in the example. Even if I remove the text color and just have the empty style that is based on the parent, the spinner appears in the middle of the screen. Has anyone discovered a way to fix this?
Edit: One more thing I forgot to mention, the style does not even update the text to be white.
Found the solution, the parent is incorrect in the example. It should be:
parent="android:style/Widget.Holo.Light.Spinner"

Categories

Resources