0

I am using the xml in my layout folder to declare my spinners. For example:

<Spinner
    android:id="@+id/foo_spinner"
    android:layout_width="0sp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="30sp" />

I load the spinner entries within my code. My problem is that the text size isn't affected. I can put 100sp there but nothing will happen. Do I have to change it only after I load the spinner content? Do I need to do this after every time I update the content?

adneal
  • 30,484
  • 10
  • 122
  • 151
Yotam
  • 10,295
  • 30
  • 88
  • 128
  • you should customize your spinner, look to this post: http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color – JpCrow Apr 02 '14 at 15:15
  • `android:textSize` isn't an attribute of [Spinner.](https://developer.android.com/reference/android/widget/Spinner.html) – adneal Apr 02 '14 at 15:38

1 Answers1

2

If you want to customize the text size Spinner item then you will have to use custom layout from Spinner item.

Suppose, create an custom TextView layout for Spinner item named custom_spinner_item.xml as follows...

<?xml version="1.0" encoding="utf-8"?>
<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:textSize="30sp" />

Now, use this layout XML to show your spinner items like:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.custom_spinner_item, list);

Another thing, you should use dp or dip instead of sp for android:layout_width attribute and android:textSize isn't appropriate for Spinner element.

<Spinner
    android:id="@+id/foo_spinner"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1" />
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
  • Thanks. Is there a way to set the style at the beginning of the code and not to update it every time I update the spinner? I'll be doing that quite often. – Yotam Apr 03 '14 at 11:47