55

I'm just wondering if it's at all possible to simply remove the dropdown arrow for a spinner? I have a drawable arrow in a backgroud layout for my spinner, however the system default arrow appears to the right of the spinner, which I would like to get rid of.

Here is the spinner xml code for my activity layout

<Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerSelectStaff"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="18dp"
            android:layout_marginRight="18dp"
            android:gravity="center"
            android:dropDownSelector="@drawable/empty"/>

And my custom spinner layout looks like this:

<TextView 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:layout_margin="5dp"
          android:gravity="center"
          android:textSize="20sp"
          android:background="@drawable/spinner_text_shape"
          android:drawableRight="@drawable/ic_keyboard_arrow_down_black_24dp"
          android:textColor="@color/primary_text" />

Thanks!

Metalor
  • 627
  • 2
  • 6
  • 5

4 Answers4

157

Background @null in the layout xml file also does the trick, if you don't want to declare a specific style:

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"/>
Galya
  • 6,294
  • 6
  • 27
  • 45
  • I were surprised that this does it very well. – Neri Jun 27 '17 at 07:41
  • is there any way to achieve this programmatically? – Mihir Patel Mar 20 '18 at 07:42
  • @MihirPatel, Spinner is View, so you can try `spinner.setBackground(null)` – Galya Mar 20 '18 at 08:30
  • Is there any way to return the default spinner arrow back after setting background null ? – Andriy Jul 10 '19 at 14:47
  • @AndriyAntoniv, you can programmatically save it as a variable, before setting the background to null and you'll have the original one to use it whenever you like. – Galya Dec 09 '19 at 08:04
  • @Galya Actually I was trying to avoid storing the default value in my own variable. IMO it would be much better to have some method provided by android which can reset Spinner background state to default – Andriy Mar 17 '20 at 15:13
25

This may help You

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style parent="@android:style/Widget.Spinner" name="SpinnerwithNoArrow">
        <item name="android:background">@android:drawable/edit_text</item>
    </style>
</resources>

Use this style in ur spinner

user2137020
  • 586
  • 8
  • 20
Prabhuraj
  • 928
  • 2
  • 8
  • 14
19

Please try this simple way:

android:background="@android:color/transparent"
Nimisha V
  • 461
  • 4
  • 12
5

Both answers were not helpful for me, so here is a really simple one-line solution that worked.

  //some spinner initialisation stuff->
mySpinner.setAdapter(adapter);

  //some spinner initialisation stuff->
mySpinner.getBackground().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

I can't tell for sure if it will work with just a default spinner layout, but it worked well with my custom that I created for other needs.

Nor Newman
  • 77
  • 1
  • 3