Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Spinner Background in android?

I want to change spinner look in android and I want it to be same for all the devices. I tried to do the same but failed to do so. If I use Tag, I am not able to customize it. I am adding screenshot of image of how I want.

http://prntscr.com/gb3oh9

like image 507
Deepanshi Gupta Avatar asked Aug 21 '17 09:08

Deepanshi Gupta


People also ask

How can I use more than one spinner in Android?

You could share the adapter between different Spinner s if they adapted the same information. Clearly each of your adapters need to adapt a different set of String s, so you need to create an ArrayAdapter for each Spinner . A single OnItemSelectedListener will work for the 3 Spinners (as long as you set them).

What is spinner in Android with example?

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.


2 Answers

Try something like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item>
    <layer-list>
       <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/white" />
                <stroke android:width="2px" android:color="@color/darkgray_7" />
                <corners android:radius="5dp" />
            </shape>
       </item>

       <item>
            <bitmap
                android:gravity="right" android:src="@drawable/arrow" />
       </item>
    </layer-list>
  </item>

</selector>
like image 89
Shaifali Rajput Avatar answered Oct 13 '22 03:10

Shaifali Rajput


Try following code for custom 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:startColor="@color/white" android:endColor="@color/appblue" />

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

            <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/drop_arrow"  android:tint="@color/red" />
        </item>
    </layer-list></item>

</selector>
like image 39
Gowthaman M Avatar answered Oct 13 '22 02:10

Gowthaman M