0

I am having a problem with the spinner item colour.
I am fetching the Spinner items from database.
I changed the spinner item colour.
But when I select a Spinner item, the colour will change to white again.

Here is my code:

 public class PersonalInformation extends Activity
     {

       @Override
       public void onCreate(Bundle savedInstanceState)
       {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info)



mySpinner.setOnItemSelectedListener(new OnItemSelectedListener()
        {
             @Override
             public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
             {
               ArrayAdapter<CharSequence> adapter =ArrayAdapter.createFromResource(this,R.array.spinner_array,R.layout.spinner_text);
             }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {
                // TODO Auto-generated method stub

            }
        });

And Here is my Spinner xml file code:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:gravity="center"
   android:paddingTop="5dp"
   android:paddingBottom="5dp"
   android:textColor="#000000"
   android:textColorHint="#000000"
   android:textSize="20dp">
</TextView>
Avijit
  • 3,834
  • 4
  • 33
  • 45
shruti lv
  • 25
  • 1
  • 7
  • this will help http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color/9476736#9476736 – Vishal Pawar Dec 26 '13 at 12:38
  • really is it changing to white or transparent? your TextView text color is #000000 which means a transparent color... – Gopal Gopi Dec 26 '13 at 13:02

1 Answers1

2

Make custom xml file for your spinner item.

spinner_item.xml:

give your customized color and size to text in this file.

<?xml version="1.0" encoding="utf-8"?>

<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:textSize="20dip"
    android:gravity="left"  
    android:textColor="#FF0000"         
    android:padding="5dip"
    />

Now use this file to show your spinner items like:

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

You don't need to set drop down resource.it will take spinner_item.xml only to show your items in spinner.

How to change spinner text size and text color?

Community
  • 1
  • 1