Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Appcompat v21 - use old spinner style

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

like image 899
dela vee Avatar asked Dec 11 '14 23:12

dela vee


2 Answers

    <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"/>
like image 80
Mahmood Abudaqa Avatar answered Sep 30 '22 15:09

Mahmood Abudaqa


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.

like image 30
reVerse Avatar answered Sep 30 '22 15:09

reVerse