2

I would like to change the default spinner icon arrow in Android with a custom image.

I made my custom spinner (based on this answer: How to customize a Spinner in Android, just changing the custom values) and it works well but I am not able to change the arrow of the spinner neither on styles or programatically.

I saw this question: How to change image of a spinner but as I do not have a Spinner tag it does not allow me to add the attribute android:spinnerSelector.

How can I replace the default arrow icon with an image?

Thanks in advance!

2 Answers 2

5

Short example:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
        this,
        R.layout.custom_spinner,
        ITEMS
);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

Then create a custom xml (named:custom_spinner.xml) for spinner:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:textSize="yourTextsize"
    android:drawablePadding="paddingValueYouWant"
    android:drawableRight="@drawable/ic_arrow_down" <!--your custom icon-->
    />

For more customization spinner, follow this artircle: How to set font custom font to Spinner text programmatically?

5
  • 2
    Ok I could add the custom dropdown arrow using android:drawableRight but now it shows both the default icon arrow and the new image icon that I have added. How can I only show the second one? Aug 4, 2016 at 9:46
  • 2
    you can give a background android:background="@drawable/bg" or android:background="@null"for spinner and it should be invisible :)
    – Huy
    Aug 4, 2016 at 9:50
  • When you put @drawable/bg do you mean to use a custom background? I tried with android:background="@null" but it does not change anything. Aug 4, 2016 at 9:57
  • oh sorry, i have never use CheckedTextview for spinner :(
    – Huy
    Aug 4, 2016 at 10:02
  • 1
    I am sorry, I had a big confusion in my head and I forgot that I was using the TextView and CheckedTextview to set the adapter to the spinner so finally I was using a Spinner :'). Now it works well using android:background="@null". Thank you very much :) Aug 4, 2016 at 10:04
1

You can directly change it in style,

<style name="CustomSpinnerTheme" parent="android:Widget.Spinner">
    <item name="android:background">@drawable/spinner_arrow</item>
</style>

Just use the drawable icon whichever you want and then set the theme in the spinner

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomSpinnerTheme"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.