NumberPicker设置宽度,设置文字颜色
修改宽度
wheel = (NumberPicker) findViewById(R.id.info_wheel_province); wheel.setLayoutParams(new LinearLayout.LayoutParams(deviceSize.x >> 1, LinearLayout.LayoutParams.WRAP_CONTENT));
修改文字颜色
public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) { boolean result = false; final int count = numberPicker.getChildCount(); for (int i = 0; i < count; i++) { View child = numberPicker.getChildAt(i); if (child instanceof EditText) { try { Field selectorWheelPaintField = numberPicker.getClass() .getDeclaredField("mSelectorWheelPaint"); selectorWheelPaintField.setAccessible(true); ((Paint) selectorWheelPaintField.get(numberPicker)).setColor(color); ((EditText) child).setTextColor(color); numberPicker.invalidate(); result = true; } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } } } return result; }
效果