Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the selected item color in the spinner?

<Spinner
     android:id="@+id/spinner1"
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"   
     android:layout_alignLeft="@+id/editText1F"
     android:layout_alignTop="@+id/txtLabel1F" 
     android:entries="@array/cat_array"  
     android:prompt="@string/cat_promt" 
     android:textColor="#ffffff"                            
   />

My Background is black and the item showing is with gray bg and black font color. But when it come to the selected it shows the font as black so it is not being seen. How do I change the color in it?

like image 480
ruchaidan Avatar asked Dec 11 '13 14:12

ruchaidan


2 Answers

You need to create a custom spinner layout to achieve what you want.

check out these questions, they have the answers you want:

How to customize a Spinner in Android

Android: Custom Spinner Layout

The idea is to create a layout for your row, and set it when creating a spinner with its adapter in code.

like image 132
JanBo Avatar answered Oct 17 '22 08:10

JanBo


Simplest use this

use this to change the text of selected Text

YOUR_SPINNER.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

 public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
     TextView selectedText=  view.findViewById(R.id.text_view_name_in_Adapter);
     selectedText.setTextColor(getResources().getColor(R.color.YOUR_COLOR));
    }
}
like image 34
Abhay Pratap Avatar answered Oct 17 '22 09:10

Abhay Pratap