android去除spinner选中背景,在Android Spinner中更改所选项目的背景颜色
您需要在适配器类中实现以下方法:它会帮助你:int selectedItem = -1;ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, list) {@Overridepublic View getDropDownView(int position, View conve
您需要在适配器类中实现以下方法:
它会帮助你:
int selectedItem = -1;
ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, list) {
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View v = null;
v = super.getDropDownView(position, null, parent);
// If this is the selected item position
if (position == selectedItem) {
v.setBackgroundColor(Color.BLUE);
}
else {
// for other views
v.setBackgroundColor(Color.WHITE);
}
return v;
}
};
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mySpinner.setAdapter(dataAdapter);
现在在下面的微调器中选择的项目
selectedItem = position;
更多推荐
所有评论(0)