Android: How to remove divider lines in number picker

blackHawk picture blackHawk · Jun 13, 2017 · Viewed 7.9k times · Source

How can I remove divider lines in number picker, I tried setShowDivider to none(seems none doesn't exist) through xml and code noting worked

picker.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);

XML:

android:showDividers="none"

enter image description here

Answer

Aditya Vyas-Lakhan picture Aditya Vyas-Lakhan · Jun 13, 2017

Set Theme for Numberpicker

<NumberPicker
   ...
   android:theme="@style/DefaultNumberPickerTheme" />

style.xml

<style name="DefaultNumberPickerTheme" parent="AppTheme">
        <item name="colorControlNormal">@color/transparent</item>
</style>

OR

private void changeDividerColor(NumberPicker picker, int color) {

    java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields();
    for (java.lang.reflect.Field pf : pickerFields) {
        if (pf.getName().equals("mSelectionDivider")) {
            pf.setAccessible(true);
            try {
                ColorDrawable colorDrawable = new ColorDrawable(color);
                pf.set(picker, colorDrawable);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (Resources.NotFoundException e) {
                e.printStackTrace();
            }
            catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            break;
        }
    }
}

And Set it as

changeDividerColor(yournumberpicker, Color.parseColor("#00ffffff"));