No_Name_Code
No_Name_Code

Reputation: 299

How to set spinner custom background in android

I am really very confusing during making custom spinner in android. I make custom but when load view after clicking spinner, custom background color display in spinner like this: enter image description here

Here, Type and Gendar are spinner. here first time load this view why display blue color part in spinner. In first i am not setting prompt but second in gender setting prompt.

What i am doing in code.

Java Code:

Spinner spinnerGender = new Spinner(this);
spinnerGender.setGravity(Gravity.CENTER_HORIZONTAL);
spinnerGender.setAdapter(new SpinAdapter(this, R.layout.custom_spinner, gender_spinner_items));
spinnerGender.setBackgroundColor(Color.WHITE);
linearGender.addView(tvGender);
linearGender.addView(spinnerGender);

**Custom layout xml file:**custom_spinner.xml****

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp" android:background="@color/purple"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/spintext"
        style="@style/spinnerDropDownItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textColor="#FFFFFF"
        android:layout_centerVertical="true"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="30dp"
        android:ellipsize="marquee"  android:singleLine="true"
        android:text="spin item" />

</RelativeLayout>

How to set select gender field in white.

Upvotes: 0

Views: 1029

Answers (1)

Stephen
Stephen

Reputation: 10059

   Try these one:

    <Spinner
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:popupBackground="Color_Code_Of_Yours"
        android:prompt="@string/display" />

Upvotes: 1

Related Questions