I have a spinner in my layout & set the prompt with android:prompt="@string/year"
.
The default prompt looks like:
Now my questions are:
- How do I change the default icon to another image?
- How to get the "Year" text appear in center with red color?
- How to change background color to yellow (background in which 'Year' text & icon exists)?
My custom Adapter class
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;
}
}