只需创建一个自定义 ArrayAdapter 并定义微调器文本视图在适配器的 getDropDownView 方法中的外观
public class CustomizedSpinnerAdapter extends ArrayAdapter<String> {
private Activity context;
String[] data = null;
public CustomizedSpinnerAdapter(Activity context, int resource, String[] data2)
{
super(context, resource, data2);
this.context = context;
this.data = data2;
}
...
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
//inflate your customlayout for the textview
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(R.layout.spinner_layout, parent, false);
}
//put the data in it
String item = data[position];
if(item != null)
{
TextView text1 = (TextView) row.findViewById(R.id.rowText);
text1.setTextColor(Color.WHITE);
text1.setText(item);
}
return row;
}
...
}
并为微调器设置此适配器
Spinner mySpinner = (Spinner) findViewById(R.id.mySpinner);
final String[] data = getResources().getStringArray(
R.array.data);
final ArrayAdapter<String> adapter1 = new CustomizedSpinnerAdapter(
AddSlaveActivity.this, android.R.layout.simple_spinner_item,
data);
mySpinner.setAdapter(adapter1);