Android : Spinner Drop-Down Customization

on Tuesday, September 2, 2014


I'm using an ActionBar with a spinner (drop-down), but the thing is that the text on the selection area itself is not supposed to be one of the elements in the list. Moreover, I'm styling the elements in the spinner using a custom adapter, which also customizes the selection area.


Probably a screenshot would be best. This is what I want to achieve: enter image description here


This is what I currently have:


enter image description here


A snippet from my custom adapter: public class CategoriesDropDownAdapter extends BaseAdapter{



@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.categories_drop_down_item, parent, false);
}
Category category = getCategory(position);
ImageView icon = (ImageView) convertView.findViewById(R.id.catIcon);
TextView title = (TextView) convertView.findViewById(R.id.catTitle);
//setting icon, title and background color
icon.setImageDrawable(category.getIcon());
title.setText(category.getTitle());
convertView.setBackgroundColor(category.getBackgroundColor());
//setting the width of the drop-down to take all the layout width
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
convertView.setLayoutParams(new LayoutParams(metrics.widthPixels, 100));

return convertView;
}
}


How can I avoid customizing the selection area (the area on the bar itself) when using a custom adapter? I want that area to be customized differently (without that triangle on the bottom-right, for instance).


0 comments:

Post a Comment