【发布时间】:2012-10-08 08:42:16
【问题描述】:
我的布局中有一个微调器,并使用android:prompt="@string/year" 设置提示。
默认提示如下:
现在我的问题是:
- 如何将默认图标更改为其他图像?
- 如何让“年份”文本以红色显示在中心?
- 如何将背景颜色更改为黄色(存在“年份”文本和图标的背景)?
我的自定义适配器类
private class MyCustomSpinnerAdapter extends ArrayAdapter<ArrayList> {
private ArrayList<String> objectsList = new ArrayList<String>();
@SuppressWarnings("unchecked")
public MyCustomSpinnerAdapter(Context context, int textViewResourceId,
ArrayList objects) {
super(context, textViewResourceId, objects);
this.objectsList = objects;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView1(position, convertView, parent);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View rowView = inflater.inflate(R.layout.spinner_dropdown, parent,
false);
LinearLayout rowTitle = (LinearLayout) rowView
.findViewById(R.id.row);
rowTitle.setBackgroundResource(R.drawable.spinner_row_focused);
TextView textView = (TextView) rowView.findViewById(R.id.title);
textView.setTypeface(typeFace);
textView.setText(objectsList.get(position).toString().trim());
return rowView;
}
public View getCustomView1(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View rowView = inflater.inflate(R.layout.spinner_dropdown, parent,
false);
TextView textView = (TextView) rowView.findViewById(R.id.title);
textView.setText(objectsList.get(position).toString().trim());
textView.setTypeface(typeFace);
return rowView;
}
}
【问题讨论】:
-
我认为你最好准备像自定义 ListView 这样的自定义微调器。
标签: android android-layout android-widget