安卓:如何在数字选取器中删除分隔线
2022-09-02 23:49:55
为数字收集器设置主题
<NumberPicker
...
android:theme="@style/DefaultNumberPickerTheme" />
风格.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"));
在 NumberPicker 中添加其中一行
XML :android:selectionDividerHeight="0dp"
或
爪哇岛:picker.setSelectionDividerHeight(0)