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?
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?
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:
How do I move the button to the right?
Note: I'm using Android Marshmallow, API level 23
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:
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
.
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 -->
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With