Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip arrow on android spinner in toolbar

I have a spinner in a toolbar at the bottom of the screen, but the arrow next to the spinner points down, which is counterintuitive. Is there any quick way to flip the arrow to point upwards instead?

enter image description here

If it helps, the spinner is defined as follows:

<Spinner
    android:id="@+id/spinner_floors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

And the row layout is just android.R.layout.simple_spinner_dropdown_item.

On another note, is there any way to change the font color to white without affecting the font color when the spinner is expanded?

Update

I managed to switch the color of the text using this answer. I also switched the background for this image so that now the code is

<Spinner android:id="@+id/spinner_floors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_arrow_drop_up_white_24dp" />

Now it looks like this:

enter image description here

How do I move the button to the right?

Note: I'm using Android Marshmallow, API level 23

like image 948
Cassidy Laidlaw Avatar asked Dec 25 '22 10:12

Cassidy Laidlaw


2 Answers

The default background of a spinner is a 9-patch drawable, so it can scale accordingly. If you want to invert the arrow you have to copy the drawable and invert it manually.

Here I took the background of the spinner found on Lollipop1 and flipped it vertically:

flipped spinner background

You can copy that and save it into the drawable-xxxhdpi folder as a 9-patch, i.e. with the extension .9.png (not just .png).

1[android-sdk]/platforms/android-22/data/res/drawable-xxxhdpi/spinner_mtrl_am_alpha.9.png


Since Marshmallow, the default background is an XML drawable (selector and vector drawable). If you only want to support Android 6.0 and newer you can copy that from the Ansroid SDK and modify it such that it is vertically flipped.

You can find the drawable in the [android-sdk]/platforms/android-23/data/res/drawable/ directory. It's named spinner_background_material.xml and depends on control_background_40dp_material.xml and ic_spinner_caret.xml.

like image 156
Floern Avatar answered Jan 08 '23 15:01

Floern


Try this

<Spinner
    android:id="@+id/spinner_floors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:background="@android:drawable/btn_dropdown" <!-- You can use your own drawable -->
     />
like image 39
Ricardo Avatar answered Jan 08 '23 16:01

Ricardo