Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to remove divider lines in number picker

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

like image 398
blackHawk Avatar asked Jun 13 '17 09:06

blackHawk


1 Answers

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"));
like image 133
Aditya Vyas-Lakhan Avatar answered Sep 22 '22 08:09

Aditya Vyas-Lakhan