I am new in android..so need a some help.. I have a xml page with white background..in it there is a spinner..the values are populating in that spinner after parsing..but problem is that when i click on that spinner the text color is also white and the background of that spinner is also white..therefore the text are not visible..i want that all the items of the spinner shiuld be of black color..i have got some threads but through that only selected item is showing black colour... need ur hlp...thnx in advance..
Asked
Active
Viewed 5,722 times
2 Answers
6
You must have implemented onItemSelected of spinner. Like this:
public class YourActivity_Name extends Activity implements
AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = (Spinner) findViewById(R.id.Spinner1);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Updated:
Then you must have set items in spinner likes this:
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
context, android.R.layout.simple_spinner_item,
array_spinner);
adapter.setDropDownViewResource(R.layout.simple_selectable_list_item);
spinner.setAdapter(adapter);
simple_selectable_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:background="?android:attr/listChoiceBackgroundIndicator"
android:paddingLeft="8dip"
android:textColor="#ff0000"
android:paddingRight="8dip"
/>

captaindroid
- 2,868
- 6
- 31
- 45
-
it only changes the color of the item at 1st position..or only the item being selected...bt i want to change color of all items whether selected or not.. – Keshri_raj Jun 18 '13 at 05:47
-
@Keshri_raj further you can write your own spinner style, like here [Style android spinner](http://stackoverflow.com/questions/13703233/style-android-spinner) – captaindroid Jun 18 '13 at 06:30
-
thanx vry much @captaindroid...it really hlpd me..god bless u.. :) – Keshri_raj Jun 18 '13 at 08:56
0
Add this layout to layout folder,
MyspinnerTextview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:textColor="#000"
android:layout_height="wrap_content"
android:gravity="center" />
And in code,
spinner=(Spinner)getActivity().findViewById(R.id.district);
ArrayAdapter<String> DisAdapter = new ArrayAdapter<String>(
YourActivity.this, R.layout.MyspinnerTextview,
yourarray);
DisAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(DisAdapter);

Basim Sherif
- 5,384
- 7
- 48
- 90
-
1it only changes the color of the item at 1st position..or only the item being selected...bt i want to change color of all items whether selected or not. – Keshri_raj Jun 18 '13 at 05:48