0
 <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  >
        <Spinner
            android:id="@+id/spinner1_day"
            android:layout_width="70dp"
            android:layout_height="40dp"
            android:src="@drawable/edit_text_style"
            android:text="Day"
            android:textStyle="normal"
            android:textSize="15dp"
            android:fontFamily="sans-serif-light"
            android:drawSelectorOnTop="true"
            android:entries="@array/Day"
            android:dropDownWidth="fill_parent"
            android:background="@drawable/downimage"/>
        <Spinner
            android:id="@+id/spinner2_month"
            android:layout_width="70dp"
            android:layout_height="40dp"
            android:background="@drawable/edit_text_style"
            android:text="Day"
            android:textStyle="normal"
            android:textSize="15dp"
            android:fontFamily="sans-serif-light"
            android:drawSelectorOnTop="true"
            android:entries="@array/Day"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.81"
            android:layout_marginLeft="10dp"
           />
    </LinearLayout>

i used android:dropDownWidth="fill_parent" and android:background="@drawable/downimage" but the image will be set as background.how can is set imageview inside the spinner at the right corner?

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42

6 Answers6

2
               <LinearLayout
                android:id="@+id/layoutSpinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/input_field"
                android:orientation="horizontal"
                android:padding="5sp">

                <Spinner
                    android:id="@+id/spinner_area"
                    android:layout_width="0sp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="9"
                    android:background="@null"
                    android:entries="@array/state"
                    android:gravity="center"
                    android:prompt="@string/area_prompt"
                    android:spinnerMode="dropdown" />

                <ImageView
                    android:id="@+id/errow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:padding="5sp"
                    android:src="@drawable/arrow1" />
            </LinearLayout>
Ramesh Bhati
  • 1,239
  • 16
  • 25
1

Use this

Create an XML in drawable folder with any name for example spinner_bg.xml and add the following lines

<?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="#ffffff" android:startColor="#ffffff" android:type="linear" />

                <stroke android:width="1dp" android:color="#504a4b" />

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

                <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
            </shape></item>
        <item ><bitmap android:gravity="bottom|right" android:src="@drawable/spinner_ab_default_holo_dark_am" />   // you can use any other image here, instead of default_holo_dark_am
        </item>
      </layer-list></item>

 </selector>  

Add the following lines to your styles.xml which is inside values folder

<style name="spinner_style" >
        <item name="android:background">@drawable/spinner_bg</item>
        <item name="android:layout_marginLeft">10dp</item>
        <item name="android:layout_marginRight">10dp</item>
        <item name="android:layout_marginBottom">10dp</item>
        <item name="android:paddingLeft">8dp</item>
        <item name="android:paddingTop">5dp</item>
        <item name="android:paddingBottom">5dp</item>

Now add this style to your spinner as

<Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/spinner_style"
            android:popupBackground="#cccccc" />

For more detail visit here. Android add arrow image to spinner

Community
  • 1
  • 1
0

Try drawableRight property in XML to set it on right side on spinner:

android:drawableRight="@drawable/downimage"
Rohit Sharma
  • 2,017
  • 1
  • 20
  • 22
0

I have solved this problem on my side by using following simple code

<RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       >

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:gravity="center"
            android:layout_height="wrap_content"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:layout_alignParentRight="true"

            android:src="@drawable/ambilwarna_arrow_down" />

    </RelativeLayout>

Hope this will work for you .Keep coding

Salman Nazir
  • 2,759
  • 2
  • 28
  • 42
0

try to create a custom spinner using FrameLayout, I using this, and works well

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@drawable/border_spinner_select_location"
    >
<Spinner
    android:spinnerMode="dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/spinner_provinsi"
    android:prompt="@string/promp"
    android:background="@drawable/spinner_pressed"
    ></Spinner>

    <ImageView
        android:layout_width="23dp"
        android:layout_height="30dp"
        android:src="@drawable/ico_arrow_select_white_xxhdpi"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="25dp"
        />
</FrameLayout>

for border line :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:thickness="0dp"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <stroke android:width="2dp"
        android:color="@android:color/white" />
</shape>

for effect when your press the spinner

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_enabled="false"
        android:drawable="@android:color/white" />
    <item android:state_pressed="true"
        android:drawable="@color/deep_white_pressed_spinner" />
    <item android:state_pressed="false" android:state_focused="true"
        android:drawable="@android:color/holo_blue_bright" />
    <item android:drawable="@color/semi_white_transparant" />

</selector>
R Besar
  • 574
  • 1
  • 5
  • 12
0

dummy.xml (drawable should be of very less size-24dp)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list android:opacity="transparent">
            <item android:width="100dp" android:gravity="right">
                <bitmap android:src="@drawable/down_button_dummy_dummy" android:gravity="center"/>
            </item>
        </layer-list>
    </item>
</selector>

layout snippet be like...

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardUseCompatPadding="true"
        app:cardElevation="5dp"
        >
     <Spinner
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/dummy">

     </Spinner>
    </android.support.v7.widget.CardView>

click here for rendered layout