Adding an Icon on a Spinner on Android
Ever since I started using spinners I keep discovering how many constrains exist in this widget. At first it was the fact that the text size/type is a challenge to customize and recently the discovery I made was on how to add an icon to the Spinner widget.
It’s quite simple to add a drawable to a TextView Widget or an EditText Widget but for a Spinner it’s not as straight forward as this.
I know someone might have struggled like me, so here are the steps I used to accomplish this.
Step 1. Create an array and a desired background “image.xml” file.
Step 2. Add the spinner widget in your layout file as follows.
Step 3. Create a layout file with the desired icon as follows.
Step 4. Listen to the spinner events and add the different spinner layouts/items on the main activity’s java file.
Final Result.
Reference Links: https://developer.android.com/guide/topics/ui/controls/spinner.html
http://android-er.blogspot.co.ke/2010/12/custom-spinner-with-icon.html