代码示例:
public class MySpinnerAdapter extends ArrayAdapter
public MySpinnerAdapter(Context context, int textViewResourceId,
String[] values) {
super(context, textViewResourceId, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.BLACK);
return textView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getDropDownView(position, convertView, parent);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.BLACK);
return textView;
}
}
// 在Activity中使用
Spinner spinner = (Spinner) findViewById(R.id.spinner); String[] values = {"item1", "item2", "item3"}; MySpinnerAdapter adapter = new MySpinnerAdapter(this, android.R.layout.simple_spinner_item, values); spinner.setAdapter(adapter);