如何删除数字选择器中的分隔线,我尝试通过xml将setShowDivider设置为无(似乎没有不存在)并且代码注意到工作
picker.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
XML:
android:showDividers="none"
为Numberpicker设置主题
<NumberPicker
...
android:theme="@style/DefaultNumberPickerTheme" />
style.xml
<style name="DefaultNumberPickerTheme" parent="AppTheme">
<item name="colorControlNormal">@color/transparent</item>
</style>
要么
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;
}
}
}
并将其设置为
changeDividerColor(yournumberpicker, Color.parseColor("#00ffffff"));
这段代码会更好
private void changeDividerColor(NumberPicker picker, int color) {
try {
Field mField = NumberPicker.class.getDeclaredField("mSelectionDivider");
mField.setAccessible(true);
ColorDrawable colorDrawable = new ColorDrawable(color);
mField.set(picker, colorDrawable);
} catch (Exception e) {
e.printStackTrace();
}
}