Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 613
N Sharma Avatar asked May 12 '14 12:05

N Sharma


2 Answers

create a xml drawable @drawable/gradient_spinner `

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item><layer-list>
        <item><shape>
            <gradient android:angle="90" android:endColor="@color/myTextPrimaryColor" android:startColor="@color/myTextPrimaryColor" android:type="linear" />

            <stroke android:width="1dp" android:color="@color/bg_eo" />

            <corners android:radius="4dp" />

            <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
        </shape></item>
        <item ><bitmap android:gravity="right|center" android:src="@drawable/expnd" />
        </item>
    </layer-list></item>

</selector> `

set spinner background android:background="@drawable/gradient_spinner"

like image 153
user829589 Avatar answered Oct 11 '22 12:10

user829589


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

like image 27
Mark Buikema Avatar answered Oct 11 '22 13:10

Mark Buikema