カスタム 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);