1

This is my Design of campaign_create.xml

enter image description here

Spinner :

        <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
            android:id="@+id/select_city"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Select Category"
            android:background="@drawable/rounded_white"
            android:textColorHint="#ffffff"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:layout_alignParentStart="true"
            android:layout_marginTop="9dp" />

@drawable/rounded_white.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
        <solid android:color="#f2f2f2"/>
        <stroke android:width="0.1dp"
            android:color="@color/white"/>
        <corners android:radius="40dp"/>
    </shape>
</item>
</selector>

I want to set background of spinner.

It is drawable file. i set property

android:background="@drawable/rounded_white"   

but it didn't work.

How to set background of spinner?

Unnati Patadia
  • 662
  • 3
  • 19
  • 39
  • https://stackoverflow.com/questions/11188398/how-to-change-the-spinner-background-design-and-color-for-android . refer this – Liya Mar 27 '18 at 10:01

3 Answers3

0

It must be working, but you won't be able to check in preview.

Try setting values(Adapter) to spinner and run the code.

But as per your layout I guess you should take Linear or Relative Layout as parent and keeping Imageview and Spinner inside.

Vir Rajpurohit
  • 1,869
  • 1
  • 10
  • 23
0

create a style for spinner like this :

  <style name="spinner_style" parent="Base.Widget.AppCompat.Spinner">
            <item name="android:background">@drawable/spinner_custom</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>
            <item name="android:popupBackground">#848484</item>
            <item  name="android:textColor">#000000</item>
        </style>

add this style in your spinner :

<Spinner
    style="@style/spinner_style"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_margin="5dp" />
Megha Maniar
  • 444
  • 5
  • 22
Sayan Manna
  • 584
  • 7
  • 13
0

i am used simple spinner control and set background used below code..

<Spinner
    android:id="@+id/mySpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/name"
    android:background="@drawable/button_selector_blue"
    />

and button_selector_blue.xml..

<?xml version="1.0" encoding="utf-8"?>

<item android:state_pressed="false">
    <layer-list>
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/colorPrimary"/>
                <padding android:left="0dp"
                    android:top="0dp"
                    android:right="0dp"
                    android:bottom="0dp"/>
                <corners android:radius="5dp" />
            </shape>
        </item>
    </layer-list>
</item>