How do i set text size of center selected value of a number picker ? and also when scrolled the size of the center number should be greater than the others.
I have tried using the following code :
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;
}
but after scroll the text size returns to normal
You can do that using XML and power of styles.
First add following to your styles.xml
<style name="MyTheme.NumberPicker">
<item name="android:textSize">11dp</item>
</style>
Then use that style in your NumberPicker like so:
<android.widget.NumberPicker
...
android:theme="@style/MyTheme.NumberPicker"
.../>
Tested on API +17
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With