Add more space between items in Android Spinner without custom style?
Unless you want a really specific spacing, I would go with one of the built in layouts.
simple_spinner_item = No line space.
simple_spinner_dropdown_item = 1 line space.
simple_dropdown_item_1line = 1.5 line space.
These and more are found in R.class
I believe Pragnani's answer is correct, but this is how I actually implemented it...
-In RES/layout, created an XML layout with just a textview in it, like shown below. This textview has the custom size / padding that I want.
spinner_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cust_view"
android:minWidth="246dp"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="left|center_vertical"
android:textColor="@android:color/black"
android:textSize="20sp"
android:paddingLeft="4dp"
android:textIsSelectable="false"/>
Then in the activity where I load my data into the spinner, when I create an ArrayAdapter for my spinner, I pass the custom textview as the second parameter to the ArrayAdapter constructor.
Spinner spinClockInWorkSite = (Spinner)findViewById(R.id.spinClockInWorkSite);
ArrayAdapter spinClockInWorkSiteAdapter = new ArrayAdapter(this, R.layout.spinner_row, this.workSiteList);
spinClockInWorkSite.setAdapter(spinClockInWorkSiteAdapter);
So now the spinner uses my custom textview that's defined in spinner_row.xml for each item in the list.
This ended up being more straight-forward for my needs than playing with the style.
Try this, Here you are not changing the spinner style, but adding the extra feature that you want for your spinner items by setting the style for Spinner Item.
<style name="spinnerStyle" parent="@android:style/Widget.TextView.SpinnerItem">
<item name="android:padding">5sp</item>
</style>
And apply style to your spinner by using style attribue
style="@style/spinnerStyle"
If you want to give satisfactory spacing then instead if all these XML and all, You can easily use "simple_spinner_dropdown_item" in spinner adapter.
Like
String [] dataList = new String[]{"Select","A","B","C","D","E"};
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, dataList);
spinner.setAdapter(dataAdapter);
It worked for me.