Search code examples
androidandroid-layoutandroid-spinner

How to add left drawable in Spinner View in Android


Hello I am trying to add left drawable in Spinner but I didn't find any propery for this as you do same in EditText using android:drawableLeft="@drawable/password_drawable". Is there any correct way to achieve same in Spinner in Android.

Here in my case there should be left drawable only this state which I gave in the screenshot, when user click on the Spinner I don't want to have left drawable there in open drop down list in Spinner

I'm trying like this where there is no such attribute

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/edittext_border"
     />

I want something like below screenshot

enter image description here

Currently it is looking like below

enter image description here

and when I set the background of the Spinner then it looks like

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/selectone_drawable"
    android:entries="@array/select_type" />

enter image description here

Thanks in advance


Solution

  • Create a nine-patch image and set it as the background of the Spinner, then add a left padding, should do the trick.