Please help me on changing the text color of the spinner.
Asked
Active
Viewed 1.6k times
2
-
1Please go through the link http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color – ranjit patel Feb 12 '13 at 13:35
-
How themes control spinner styling is explained here: http://tekeye.biz/2012/changing-android-spinner-text-size – Daniel S. Fowler Feb 13 '13 at 00:43
2 Answers
6
try this:
Spinner spinner = (Spinner)findViewById(R.id.my_spinner);
TextView tv = (TextView) spinner.getSelectedView();
tv.setTextColor(Color.BLACK);
otherwise change in spinner_xml:
<?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"
/>

SubbaReddy PolamReddy
- 2,083
- 2
- 17
- 23
-
1be carefull, getSelectedView() should be called AFTER an item is selected. – M. Usman Khan Mar 07 '14 at 06:57
6
Try this
custom_spinner_item.xml
<?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="fill_parent"
android:gravity="top"
android:singleLine="true"
android:textColor="@color/iphone_text" />
In Java code
Spinner spnCategory= (Spinner)findViewById(R.id.my_spinner);
..
ArrayAdapter<String> adptSpnCategory = new ArrayAdapter<String>this,R.layout.custom_spinner_item, alCategoryName);
adptSpnCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCategory.setAdapter(adptSpnCategory);
spnCategory.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
}
public void onNothingSelected(AdapterView<?> arg0)
{
}
});

Rajesh Rajaram
- 3,271
- 4
- 29
- 48
-
but it increase size of spinner also. In my case I make transparent spinner view and place it nearer view. So if follow above mention it affect spinner dialog and spinner view size as well...any other suggestion ? – CoDe Jul 15 '14 at 13:11