How to make spinner background transparent in android?
Asked Answered
I

5

8

Here is my spinner layout,

<Spinner
    android:layout_marginLeft="20dp"
    android:background="@android:drawable/btn_dropdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/spinnerQuality"
    android:layout_gravity="center_horizontal"
    />

and spinner item layout,

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:paddingTop="10dp"
    android:paddingLeft="10dp"/>

and showing spinner is, enter image description here

But i want to get both spinner and dropdown items background transparent. How would i get that?

Instrumentality answered 18/5, 2015 at 6:58 Comment(0)
G
17

Try this //to change the dropdown background

android:popupBackground="@android:color/transparent"

//to change the spinner background

  android:background="@android:color/transparent"
Gupta answered 18/5, 2015 at 7:1 Comment(2)
Its working for dropdown item layout but how to do for main spinner layout?Instrumentality
Is not this change hide down arrow sign (indicator) of spinner layout?Instrumentality
S
3

Set:

android.popupBackground="@null"
Soberminded answered 31/1, 2017 at 6:52 Comment(0)
I
3

try this code:

        <Spinner
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dip"
        android:theme="@style/SpinnerTheme"
        android:popupBackground="@android:color/transparent"/>

add style in res/values/styles.xml

<style name="SpinnerTheme">
    <item name="colorAccent">@color/blue_pastels</item>
    <item name="colorControlNormal">@color/blue_pastels</item>
</style>
<style name="RadioButtonStyle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorControlNormal">@color/black</item>
    <item name="colorAccent">@color/black</item>
    <item name="android:textColor">@color/black</item>
</style>

in java code add :

    spinner.setOnItemSelectedListener(this);
    List type = new ArrayList();
    type.add("12");
    type.add("13");
    type.add("14");
    type.add("11");
    ArrayAdapter dataAdapter = new ArrayAdapter(context, R.layout.spinner_item, type );
    dataAdapter.setDropDownViewResource(R.layout.spinner_item_dropdown);
    spinner.setAdapter(dataAdapter);

create res/layout/spinner_item.xml and add this code:

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

android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:gravity="center"
android:textColor="@color/white_00" />

create res/layout/spinner_item_dropdown.xml and add this code:

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

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black"
android:gravity="center_vertical"
android:paddingStart="12dip"
android:paddingEnd="7dip"
android:layout_margin="20dip"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:ellipsize="marquee"
android:theme="@style/RadioButtonStyle"
android:textSize="14sp"

android:background="@color/TRANSPARENT"
android:backgroundTint="@color/theme_gray_10"
android:backgroundTintMode="src_over"
/>
Indemonstrable answered 8/10, 2019 at 12:11 Comment(0)
S
0

Apply

android:background="@android:color/transparent"

to textview and see if it helps.

Suetonius answered 18/5, 2015 at 7:1 Comment(1)
when i remove android:background="@android:drawable/btn_dropdown" its not showing down arrow. I also need to show this.Instrumentality
J
0

Use

<Spinner
 android:background="@null"
 android:popupBackground="@android:color/transparent"/>
Jungian answered 18/5, 2015 at 7:4 Comment(1)
where i remove android:background="@android:drawable/btn_dropdown" its not showing down arrow. I also need to show this.Instrumentality

© 2022 - 2024 — McMap. All rights reserved.