-1

I want to set color for hint in the spinner. Please help me... Here is my spinner.

    List<String> catagories = new ArrayList<>();
    catagories.add("General");
    catagories.add("OBC");
    catagories.add("SC/ST");

    Spinneradapter adapter = new 
         Spinneradapter(this,android.R.layout.simple_spinner_dropdown_item);
    adapter.addAll(catagories);
    adapter.add("Select Category");
    spinner.setAdapter(adapter);
    spinner.setSelection(adapter.getCount());
akash bs
  • 258
  • 6
  • 15
  • There is a thing called "Google". follow this answer and you will get what you are looking for, https://stackoverflow.com/questions/9611220/how-do-you-set-the-spinner-text-color – Umair Dec 14 '17 at 06:24
  • https://stackoverflow.com/questions/37019941/how-to-add-a-hint-in-spinner-in-xml – coder_baba Dec 14 '17 at 06:25

2 Answers2

1

Create custom XML file for your spinner item.

spinner_item.xml:

Give your customized color and size to text in this file.This is will be for your spinner item text style.

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

<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:textSize="20sp"
    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 the drop down resource. It will take spinner_item.xml only to show your items in spinner.

Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39
1

In your getView() of SpinnerAdapter you should add these lines to set the text color of item on 0 index:

        TextView names = (TextView) view.findViewById(R.id.textView);
        names.setText(dataList[i]);

        if (i == 0) {
            // Set the hint text color gray
            names.setTextColor(context.getResources().getColor(R.color.color_hint));
        } else {
            names.setTextColor(context.getResources().getColor(R.color.color_text));
        }
Stuti Kasliwal
  • 771
  • 9
  • 20