This is my spinner\'s code:
Spinner food = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter foodadapter = ArrayAdapter.createFromResou
If you only want to increase the size, that the dropdown is good touchable, then you simply can change the simple_spinner_item to simple_spinner_dropdown_item:
ArrayAdapter.createFromResource(this, R.array.item_array, android.R.layout.simple_spinner_dropdown_item);
---------------------------^
Just to help others in case they are statically setting their Spinner entries in XML.
The above answers work if you're creating your Spinner via code but if you're setting your Spinner entries via XML, i.e. using android:entries
, then you can adjust the text size and other attributes with the following two theme settings:
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- For the resting Spinner style -->
<item name="android:spinnerItemStyle">
@style/spinnerItemStyle
</item>
<!-- For each individual Spinner list item once clicked on -->
<item name="android:spinnerDropDownItemStyle">
@style/spinnerDropDownItemStyle
</item>
</style>
<style name="spinnerItemStyle">
<item name="android:padding">10dp</item>
<item name="android:textSize">20sp</item>
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="spinnerDropDownItemStyle">
<item name="android:padding">20dp</item>
<item name="android:textSize">30sp</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
private OnItemSelectedListener spinner = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLACK);
((TextView) parent.getChildAt(0)).setTextSize(10);
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
Save the below xml as spinner_layout.xml in layout folder
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="13sp"
/>
change the textSize which you want. and use the below adapter code to fill it.
Spinner food = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(
this, R.array.item_array, R.layout.spinner_layout);
foodadapter.setDropDownViewResource(R.layout.spinner_layout);
food.setAdapter(foodadapter);
The above solutions are all hard coded in the xml.
There is an alternative solution which allows you to change it programmatically. https://stackoverflow.com/a/11494962/5089713 Once you have the TextView, you can do whatever with it, for instance change the font size.
your code then looks like
Spinner food = (Spinner) findViewById(R.id.spinner1);
CharSequence[] strings = getActivity().getResources().getTextArray(R.array.item_array);
ArrayAdapter<CharSequence> foodadapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, strings){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view =super.getView(position, convertView, parent);
TextView textView=(TextView) view.findViewById(android.R.id.text1);
// do whatever you want with this text view
textView.setTextSize(20);
return view;
}
};
foodadapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
food.setAdapter(foodadapter);