How to change the spinner background in Android?

how to change spinner background color in android programmatically
android-spinner background arrow
how to change spinner text color in android
spinner in android
custom spinner android
android spinner text color is white
android spinner style
change spinner dropdown icon android

I am developing an app in which I need to change the spinner background layout to match the background color. I researched and found that I need to create a 9 patch image. I have done creating the 9 patch image and used in the app but it looks bigger than the normal spinner and also I couldn't see the drop down button in the spinner as well.

I am so happy if you guys provide me a clear tutorial from start creating the 9 patch image for Spinner and using it in the app.

Code for the Spinner

 <Spinner
        android:id="@+id/spnIncredientone"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtMixtureTitle" 
        android:layout_marginLeft="5dip"
        android:layout_marginRight="5dip"
        android:background="@drawable/spinner_background"
        android:prompt="@string/selectmixture" />

You can set the spinners background color in xml like this:

android:background="YOUR_HEX_COLOR_CODE"

and if you use the drop down menu with you spinner you can set its background color like this:

android:popupBackground="YOUR_HEX_COLOR_CODE"

how can i change spinner background color?, You can simply add the following code inside <Spinner/> to change popup background. Happy Coding..!! Add the following in your styles. xml to change the background color and text color of dropdown. Background color makes the spinner items look different then the whole layout background because they look more bright and colorful. This type of functionality can be possible when we have add extra textview_with_background.xml file into our project and set the textview into spinner.

You can change background color and drop down icon like doing this way

Step1: In drawable folder make background.xml for border of spinner.

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="5dp" />
<stroke
    android:width="1dp"
    android:color="@color/darkGray" />
</shape>  //edited

Step2: for layout design of spinner use this drop down icon or any image drop.pnj

  <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight=".28"
                    android:background="@drawable/spinner_border"
                    android:orientation="horizontal">

                    <Spinner
                        android:id="@+id/spinner2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:background="@android:color/transparent"
                        android:gravity="center"
                        android:layout_marginLeft="5dp"
                        android:spinnerMode="dropdown" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:src="@mipmap/drop" />

                </RelativeLayout>

Finally looks like below image and it is every where clickable in round area and no need of to write click Lister for imageView.

For more details , you can see Here

Custom Spinner Background Design in android, As other widgets having drawable setting options as left or right to it but Spinner widget does not take drawable setting options . In a project the job was to do a  Change spinner background. Ask Question For more Information Check this Change Spinner Style In Android. share | improve this answer. answered Nov 21 '12 at 9:34.

Even though it is an older post but as I came across it while looking for same problem so I thought I will add my two cents as well. Here is my version of Spinner's background with DropDown arrow. Just the complete background, not only the arrow.

This is how it looks..

Apply on spinner like...

<Spinner
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/spinner_bg" />

spinner_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/InputBg" />
    </item>
    <item android:gravity="center_vertical|right" android:right="8dp">
        <layer-list>
            <item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="10dp">
                <rotate
                    android:fromDegrees="45"
                    android:toDegrees="45">
                    <shape android:shape="rectangle">
                        <solid android:color="#666666" />
                        <stroke android:color="#aaaaaa" android:width="1dp"/>
                    </shape>
                </rotate>
            </item>
            <item android:width="30dp" android:height="10dp" android:bottom="21dp" android:gravity="center">
                <shape android:shape="rectangle">
                    <solid android:color="@color/InputBg"/>
                </shape>
            </item>
        </layer-list>
    </item>
</layer-list>

@color/InputBg should be replaced by the color you want as your background.

First it fills the background with desired color. Then a child layer-list makes a square and rotates it by 45 degrees and then a second Rectangle with background color covers the top part of rotated square making it look like a down arrow. (There is an extra stroke in rotated rectangle with is not really required)

How to change the spinner background design and color for android , I am developing an app in which I need to change the spinner background layout to match the background color I researched and found that A good way to customise spinners and any other Android controls is to use the Android Asset Studio site and choose the Android Holo Colors Generator. This will create all the assets you might need, including the "underline". It also generates the XML files that implement the changes.

Spinner code

<Spinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/text.white"
    android:paddingBottom="13dp"
    android:background="@drawable/bg_spinner"/>

bg_spinner.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/colorPrimaryDark"/>
            <corners android:radius="10dp" />
        </shape>
    </item>
    <item android:gravity="center_vertical|right" android:right="8dp">
        <layer-list>
            <item android:width="12dp" android:height="12dp"  android:gravity="center" android:bottom="10dp">
                <rotate
                    android:fromDegrees="45"
                    android:toDegrees="45">
                    <shape android:shape="rectangle">
                        <solid android:color="#ffffff" />
                        <stroke android:color="#ffffff" android:width="1dp"/>
                    </shape>
                </rotate>
            </item>
            <item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center">
                <shape android:shape="rectangle">
                    <solid android:color="@color/colorPrimaryDark"/>
                </shape>
            </item>
        </layer-list>
    </item>
</layer-list>

How to change Spinner item background color in Android, Spinner item background color in Android. activity_main.xml. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  Want to change spinner color until press the next spinner. Need to change the spinner background color You need to override the android style of spinner

As Jakob pointed out, android:popupBackground is the key attribute for the dropdown (opened state of the Spinner), but instead of using just a colour, I got the best results with a 9-patch drawable like this:

menu_dropdown_panel.9.png

Note that it's very easy to generate this 9-patch image for the background colour of your choice, for example using this online tool as I explained in this answer!

So, my Spinner XML definition looks like:

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/navigationBlue"
    android:spinnerMode="dropdown"
    android:popupBackground="@drawable/menu_dropdown_panel"
    />

And the result:

(For custom fonts, as in the screenshot above, a custom SpinnerAdapter is needed too.)

Works at least on Android 4.0+ (API level 14+).

Custom Spinner background with border XML, Make your spinner border and background like below image: Create an android project. encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.​android.com/apk/res/android" Now go to your spinner then set background. Android SQLite Join Multiple Tables Example - 124,360 views Android Vertical ScrollBar Styling - 94,713 views Android: How to get Holo Spinner Theme in Android 2.x? - 84,097 views

Custom Spinner background with border XML, You can set the spinners background color in xml like this: android:background="​YOUR_HEX_COLOR_CODE". and if you use the drop down  Unfortunately, there is no way you can do this from your xml except by using android:background="@drawable/spinnerBackground", but this will change your spinner background completely. So you have to create a new xml in your values folder called colors.xml and add a color there called red.

Spinner, Make your spinner border and background like below image: Create an android project. Now go to your spinner then set background. The solutions I found to change the spinner dropdown icon where all: Set the drawable as the spinner background: <Spinner android:layout_width="match_parent

Android Custom Spinner Dropdown Arrow Background Border Icon , Gravity setting for positioning the currently selected item. android:​popupBackground, Background drawable to use for the dropdown in  Setting a search hint or prompt text in android spinner is not a tough task. But customizing them like changing text color, changing background color need little tricks. We will use two methods to implement search hint. First by creating a drop down menu and second by using prompt dialog.

Comments
  • Android: Custom Spinners
  • check this answer for update.
  • how about the text inside the dropdown menu with the spinner?
  • if i remember correctly, then you can only define that by the android:textcolor attribute of the spinner. So the text color in the drop down menu unfortunately has to be the same as the spinner widgets text color.
  • An answer like this should be at the top
  • Arrow disappears this way
  • @steven solution for disppeared arrow - check out this
  • Does it have a dropdown menu?
  • Yes, Looking nice Drop down menu
  • That works great! Can I ask why the ImageView can trigger the pull-down menu automatically?
  • @MikeYan , it doesn't. There is relative layout, spinner width is "match_parent", so the imageView is drawn above spinner. Image doesn't handle clicks, so they are delivered to spinner
  • thanks nashe, but the text is not shrinking, its overlapping with down arrow. how to shrink the text so it wont overlap the down arrow?