Home » Android » Customize android spinner to have dropdown icon + full width dropdown

Customize android spinner to have dropdown icon + full width dropdown

Posted by: admin November 1, 2017 Leave a comment


Variations of this questions are already available, but I didn’t found exact duplicate. So here is my question. I want to have full width dropdown + dropdown icon in the android spinner.

I’ve tried with wrapping it in relative layout, then since spinner doesn’t have the full width so the dropdown items. Probably relative layout with imageview will work, but I am looking for more clean solution. Below is the one with relative view approach.

Dropdown item doesn't get full width

I’ve tried with setting background drawable with dropdown icon bitmap, then it works but since dropdown item goes full width, icon cannot be seen. Below is the result + code. As you can see 2nd spinner doesn’t have items, so it shows the icon.

background is covered by the textview(custom dropdown layout)

Spinner spinner = new Spinner(ctx); 
LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); 
layoutParams.bottomMargin = dpToPx(10); 
spinner.setAdapter(new ArrayAdapter<>(ctx, R.layout.spinner_dropdown, values)); 

How can I achieve below result? I want to do this programatically.

Expected Result