15

I have a spinner with a LOOONG list of items. What I noticed is that whenever I try to scroll the spinner items SLOWLY, it suddenly takes me back to the top of the spinner selection. I'm just using a standard Spinner with a simple ArrayAdapter. It's not really an issue, but it's kinda annoying that whenever a user would scroll slowly, the selection resets all the way to the top. You can fling the list, but if you scroll slowly, keeping your finger on the screen, it scrolls back up to the top of the list.

Has anyone else experienced this problem? Why does it occur? Is there a way to "fix" this issue?

Note: The problem I have is only on a Spinner.

2

2 Answers 2

1

I had exactly the same issue and removing the app:popupTheme attribute fixed it. Check this comment: https://issuetracker.google.com/issues/37065626#comment15.

0

I solved this issue by the following method.

  • API level 22 or lower: Use app:popupTheme
  • API level 23 or higher: Use android:popupTheme

res/layout/spinner.xml

<android.support.v7.widget.AppCompatSpinner
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
    android:layout_marginRight="@dimen/toolbar_spinner_margin_right"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

res/layout-v23/spinner.xml

<android.support.v7.widget.AppCompatSpinner
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
    android:layout_marginRight="@dimen/toolbar_spinner_margin_right"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

res/layout/activity_main.xml

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <include layout="@layout/spinner" />

</android.support.v7.widget.Toolbar>

spinner button color is black

And to solve an issue where the spinner button color is black in API level 19 or lower, you need to add the following code:

Kotlin

if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
    val spinnerDrawable = spinner.background.constantState.newDrawable()
    spinnerDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP)
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        spinner.background = spinnerDrawable
    } else {
        spinner.setBackgroundDrawable(spinnerDrawable)
    }
}

Java

if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
    Drawable spinnerDrawable = spinner.getBackground().getConstantState().newDrawable();
    spinnerDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        spinner.setBackground(spinnerDrawable);
    } else {
        spinner.setBackgroundDrawable(spinnerDrawable);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.