spinner dropdown start from top of spinner
Asked Answered
C

3

14

Problem is Spinner dropdown list start from top line of Spinner but it should be start from bottom line of Spinner

Normal state

enter image description here

After Click

enter image description here

Spinner xml code

<Spinner
    android:id="@+id/spnSelectLanguage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:layout_marginTop="16dp"
    android:spinnerMode="dropdown"
    android:background="@drawable/spn_lang_dropdown_selector"
    android:gravity="center_vertical"
    android:popupBackground="#EAEAEA"
    android:textColor="#54a4db" />

Code

Spinner spnSelectLanguage = (Spinner)rootView.findViewById(R.id.spnSelectLanguage);
    ArrayAdapter<String> adapterLanguage= new ArrayAdapter<String> (context,R.layout.layout_lng_spinner_item,new String[]{"English","Arabic"});
    adapterLanguage.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spnSelectLanguage.setAdapter(adapterLanguage);

Style.xml

<style name="SpinnerStyle" parent="android:style/Widget.ListView.DropDown">
    <item name="android:divider">@color/grey</item>
    <item name="android:dividerHeight">1dp</item>
</style>
Colorable answered 12/12, 2015 at 9:4 Comment(1)
it's nothing but drawable selector. you can put anything as background.Colorable
L
23

In your spinner:

android:overlapAnchor="false"

NOTE If you are supporting API below 21, this attribute has to be copy and pasted as it is available for API >= 21.

Lorimer answered 21/2, 2016 at 20:49 Comment(1)
beautiful! Spent almost 16 hours finding what can be done so that the popup dropdown of AppCompatSpinner in my layout does not overlap the spinner view. You Rock! This should be the selected answer. NOTE This attribute has to be copy and pasted as it is available for API >= 21Bonnet
L
16

You can to set this lines in your Spinner xml code:

android:spinnerMode="dropdown"
android:dropDownVerticalOffset="50dp"

With this, your dropdownview will start with top offset. You can hardcode the offset number or calculate it at runtime and use:

setDropDownVerticalOffset(int pixels)

More in: Android Spinner

Linc answered 14/7, 2016 at 11:2 Comment(0)
A
0

For me worked only when I created spinner style and added the "android:spinnerStyle" item to style of my theme.

I opened my /res/values/styles.xml, found my theme ("AppTheme") and added <item name="android:spinnerStyle">@style/custom_spinner</item> like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>            
    <item name="android:spinnerStyle">@style/custom_spinner</item>
</style>

<style name="custom_spinner" parent="@android:style/Widget.Holo.Light.Spinner">
</style>
Astylar answered 28/6, 2018 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.