如何设置数字选择器(Number Picker)中心选定值的文本大小?并且当滚动时,中心数字的大小应该比其他数字更大。
我尝试使用以下代码:
public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) {
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);
((EditText) child).setTextSize(48);
numberPicker.invalidate();
return true;
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
Log.w("setNumberPickerTextColor", e);
}
}
}
return false;
}
但是在滚动后,文本大小会恢复到正常。