Android Appcompat v21 - use old spinner style
Asked Answered
D

2

11

I am using appcompat v21 in a project, but I do not like the new spinner it comes with by default. This new spinner comes only with a small downward-facing arrow that indicates it presence. I would prefer the old spinner used in 4.x versions of android which come with an EditText-like feature underlining the widget's content and an arrow in the bottom right corner.

How can I achieve this spinner style while still using appcompat v21?

The udesired spinner style:

photo of undesired spinner:

photo of undesired spinner

photo of desired spinner:

photo of desired spinner

Devan answered 11/12, 2014 at 23:2 Comment(0)
N
30

You can simply set the Style of the Spinner to Widget.Holo.Light.Spinner

Example

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@android:style/Widget.Holo.Light.Spinner" />

This will give you the old Spinner-Style back though there are two drawbacks:

  1. This solution only works with API-Level 14 and up (no that big of a deal)
  2. The appearance of the DropDown Popup-Window is managed by the "framework" - this means on pre Lollipop devices the Popup-Window will appear below the Spinner. Starting with Lollipop it'll be above the Spinner (afaik there's no way to change this). With regard to this see the following comparison (on the left pre Lollipop)

spinner comparison

If you wish to customize the rows of the DropDown you can do so by calling setDropDownViewResource(int) on the adapter of the Spinner with the reference to your own layout.

Nugget answered 12/12, 2014 at 23:52 Comment(1)
@Nugget : But when I use "/Widget.Material.Light.Spinner", it still shows dark theme for lollipop and above.Conversion
K
2
    <Spinner
    android:id="@+id/spinner_nav"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    android:overlapAnchor="false"
    style="@style/Platform.Widget.AppCompat.Spinner"/>
Koziara answered 3/1, 2017 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.