因为这是因为您为您的应用程序设置了主题。您需要为此实现自定义适配器类并实现 SpinnerAdapter。
这是这个的例子
public class CusSpinnerAdapter extends ArrayAdapter<String>
implements SpinnerAdapter{
private LayoutInflater inflate;
private int resourceId;
private String[] options;
private int selIndex;
private Context context;
public CusSpinnerAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.inflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.resourceId = textViewResourceId;
this.options = objects;
}
public void setSelectedIndex(int selIndex){
this.selIndex = selIndex;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView = inflate.inflate(resourceId, null);
Holder holder = new Holder();
holder.textView = (TextView)convertView.findViewById(R.id.spinner_item);
convertView.setTag(holder);
}
Holder holder = (Holder)convertView.getTag();
holder.textView.setText(options[position]);
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView = inflate.inflate(resourceId, null);
Holder holder = new Holder();
holder.textView = (TextView)convertView.findViewById(R.id.spinner_item);
convertView.setTag(holder);
}
Holder holder = (Holder)convertView.getTag();
holder.textView.setText(options[position]);
if(position==selIndex){
holder.textView.setBackgroundColor(context.getResources().getColor(R.color.spinner_item_selected));
}else
holder.textView.setBackgroundColor(context.getResources().getColor(R.color.spinner_item_default));
return convertView;
}
private class Holder{
TextView textView;
}
}
在这个 selIndex 中被选中的索引项。当您确定选择了哪个项目并为您的项目设置选定的可绘制对象时,您需要实现这一点。只需在微调器控件的选定项目上实现,并从中设置此适配器类的索引值。
这也是另一种方式
https://stackoverflow.com/a/4662939/760489