I created a customer spinner and don't get rid of white spaces when the popup appears:
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.