1

I created a customer spinner and don't get rid of white spaces when the popup appears:

Popup

That's how I created the custom spinner:
I copied simple_spinner_dropdown_item.xml and simple_spinner_item.xml from installation directory to my layout folder and changed the style attributes so that they point to my own style:

simple_spinner_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    ...
    style="@style/spinnerItemStyle" />

simple_spinner_dropdown_item.xml

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
...
style="@style/spinnerDropDownItemStyle" />

spinnerItemStyle.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">
        <item name="android:textColor">#FFF</item>
        <item name="android:textSize">12sp</item>
        <item name="android:background">@null</item>
    </style>
</resources>

spinnerDropDownItemStyle.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.DropDownItem">
        <item name="android:textColor">#FFF</item>
        <item name="android:padding">20dp</item>
        <item name="android:textSize">12sp</item>
        <item name="android:background">@drawable/spinner_rectangle</item>
    </style>
</resources>

spinner_rectangle.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#333" />
    <stroke
        android:width="0dip" />
</shape>

The spinner is simply referenced within the layout file of the Activity:

        <Spinner 
            android:id="@+id/preferences_spinner_language"
            android:background="@drawable/spinner_dropdown" />

And I don't use a custom Adapter, just the usual ArrayAdapter where I use the both resources from above and not the Android resources:

Spinner spinner = (Spinner)findViewById(R.id.preferences_spinner_language);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.preferences_language_array, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

I guess that there is some underlying ImageView which produces these white borders. How can I access it and get rid of these border or colorize them? I would prefer a solution where I don't have to create an own ArrayAdapter.

Bevor
  • 8,396
  • 15
  • 77
  • 141
  • hope it helps! http://stackoverflow.com/questions/10916658/android-cannot-style-spinner-divider/13144302#13144302 – Arash GM Jul 06 '13 at 11:30
  • Unfortunately not, because there is no Theme.Holo in Android 2.3.3. And `android:dropDownListViewStyle` does not exist in my parent theme I use. I already created my own theme due to other reasons and derive from `parent="android:Theme"` – Bevor Jul 06 '13 at 12:51

1 Answers1

0

In your theme, override the android:dropDownListViewStyle style. Eg:

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:dropDownListViewStyle">@style/MySpinnerStyle</item>
</style>

<style name="MySpinnerStyle" parent="android:style/Widget.ListView.DropDown">
    <item name="android:divider">#FFEEEEEE</item>
    <item name="android:dividerHeight">1dp</item>
</style>
Paul Burke
  • 25,496
  • 9
  • 66
  • 62
  • I don't know how this should work. I already overwrite my theme since I use a custom theme for my whole app (parent="android:Theme"). And in my current theme, I have no items like android:dropDownListViewStyle (content assist of Eclipse doesn't show such suggestions). That's why all other threads with similar questions were not helpful to me. – Bevor Jul 06 '13 at 12:11
  • If your parent theme is `android:Theme` this value is already set for you. Have you tried adding the `android:dropDownListViewStyle` tag to your custom theme? – Paul Burke Jul 06 '13 at 12:20
  • I tried to use my own theme as parent or parent="android:Theme", because there is no Theme.Holo in Android 2.3.3, but the divider stays white. (Although I changed in AndroidManifest my custom theme to the derived theme). I tried to add `@style/MySpinnerStyle` with its declaration to my custom theme, but still no change. – Bevor Jul 06 '13 at 12:34
  • I know it's been years, but have you solved this issue? I'm having the exact same problem and I've tried everything around, but no luck :/ – arvere May 22 '18 at 11:43