3

I am using a Spinner in my app. I used the basic spinner and this is my code:`

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/SpinnerSpinnerTheme"
    android:spinnerMode="dropdown"
    android:layout_gravity="center_vertical"
    android:id="@+id/hj_order_date_spinner"
    />`

and this is how i instantiated in my activity

 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.hj_spinner_items,android.R.layout.simple_spinner_item);
   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dateSpinner.setPrompt("Sort By");
    dateSpinner.setAdapter(adapter);

This works fine in android 4.4.4 but on Nexus 5(using Lollipop) the drop down list/Popup changes it's position and hides the "Sort By" bar or the original spinner. Can anyone provide any insight as to what might be the issue?

Saurabh
  • 434
  • 1
  • 4
  • 19
  • 1
    Please explain the issue that you're seeing in more detail. The position changes in what way? – alanv Mar 08 '15 at 07:47
  • the popup covers the original spinner. It's top should be aligned the bottom of the Spinner View but in Nexus 5 it's top is aligned with the top of the Spinner View, so the spinner prompt text is hidden behind the popup window. – Saurabh Mar 08 '15 at 08:03
  • 1
    That's how spinners are supposed to look when using the Material theme. You can set android:overlapAnchor="false" if you don't want it to look like a Material spinner. – alanv Mar 08 '15 at 08:05
  • It worked. Please make that a formal answer so I can mark it as correct – Saurabh Mar 08 '15 at 08:34

1 Answers1

16

You can specify whether the spinner drop-down should overlap the anchor by using the android:overlapAnchor attribute. When using the Material spinner style, this attribute defaults to true.

<Spinner
    ...
    android:overlapAnchor="false" />
alanv
  • 23,966
  • 4
  • 93
  • 80
  • Do you know perhaps how to make it work like on G+ ? so that the window will take the entire width? If so, please answer here: http://stackoverflow.com/q/31773105/878126 – android developer Aug 03 '15 at 14:33
  • 1
    How do you get this effect pre-lollipop? it seems not to effect previous OS versions. – Jack.Ramsden Jan 18 '16 at 09:02