Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I increase the spinner list item font size?

This is my spinner's code:

Spinner food = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(         this, R.array.item_array, android.R.layout.simple_spinner_item); foodadapter.setDropDownViewResource(android.R.layout.simple_spinner_item);         food.setAdapter(foodadapter); 

This is a part of the layout file where I have created the spinner:

<Spinner         android:id="@+id/spinner1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentRight="true"         android:layout_alignParentTop="true"         android:layout_toRightOf="@+id/textView1" /> 

This is the item_array:

<resources>     <string name="item_picker">Select an iten</string>     <string-array name="item_array">         <item>Pizza</item>         <item>Burger</item>         <item>Sandwiches</item>         <item>Bread</item>         <item>Pastries</item>         <item>Snackers</item>     </string-array> </resources> 

Note: I do not want a simple_spinner_dropdown_item.

I just want to increase the size of the list items. How can I do that?

like image 906
divaNilisha Avatar asked May 02 '12 08:05

divaNilisha


People also ask

What is spinner in Android with example?

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.


2 Answers

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); 
like image 94
V.J. Avatar answered Sep 25 '22 13:09

V.J.


Via XML Only

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:

In your 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> 
like image 33
Joshua Pinter Avatar answered Sep 21 '22 13:09

Joshua Pinter