Android NumberPicker rendering scrollbars when loading view

372 Views Asked by At

I am building a small app that uses NumberPickers. Everything is working as expected except that when navigating to the fragment that contains the pickers it shows small scrollbars the top right corner of each NumberPicker, and then they disappear after a few seconds.

small rectangles in NumberPicker

I thought it was to do with them gaining focus when I navigate to the fragment and have set android:descendantFocusability="blocksDescendants" on them to no avail. The issue also occurs when I set <requestFocus /> on another element and it is not affected by disabling scroll indicators.

I am not doing any custom styling, the code for the pickers is:

<NumberPicker
        android:id="@+id/forTimeSecondsPicker"
        android:layout_width="90dp"
        android:layout_height="240dp"
        android:layout_marginTop="206dp"
        android:layout_marginEnd="90dp"
        android:descendantFocusability="blocksDescendants"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"></NumberPicker>

In the .kt file they are initialised as

private var workSecondsPicker : NumberPicker? = null

and I set the values like this

workSecondsPicker = requireView().findViewById(R.id.forTimeSecondsPicker)
    workSecondsPicker?.minValue = 0
    workSecondsPicker?.maxValue = 59
    workSecondsPicker?.value = WORK_SECONDS_DEFAULT

One weird observation, when running the app on my physical device (Pixel 4) and on the emulator (Pixel 3a) the issue does not occur when first running the app. However, if I navigate to the Settings screen (androidx.preference) from anywhere inside the app and then navigate back to one of the fragments with NumberPickers the scrollbars appear every time until restarting the app, this behaviour is reproducible and consistent.

I target sdk 30 (min 23) and am using Android Studio 4.1.2.

1

There are 1 best solutions below

1
Myshkin On

Took me a while to even realise these things were scrollbars and still not sure why they only appeared after visiting the preferences screen but setting

android:scrollbarSize="0dp"

did the trick.