public static void SetNumberPickerFont(NumberPicker numberPicker, Typeface fontFamily, float textSizeInSp) { int count = numberPicker.ChildCount; for (int i = 0; i < count; i++) { Android.Views.View?child = numberPicker.GetChildAt(i); if (child is EditText editText) { try { Java.Lang.Reflect.Field selectorWheelPaintField = numberPicker.Class .GetDeclaredField("mSelectorWheelPaint"); selectorWheelPaintField.Accessible = true; ((Paint)selectorWheelPaintField.Get(numberPicker) !).TextSize = textSizeInSp; editText.Typeface = fontFamily; editText.SetTextSize(Android.Util.ComplexUnitType.Px, textSizeInSp); numberPicker.Invalidate(); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("SetNumberPickerFont failed.", e); } } } }
static void SetNumberPickerTextColor(NumberPicker numberPicker, Color color) { try { int count = numberPicker.ChildCount; for (int i = 0; i < count; i++) { View child = numberPicker.GetChildAt(i); if (child is EditText) { try { Field selectorWheelPaintField = numberPicker.Class .GetDeclaredField("mSelectorWheelPaint"); selectorWheelPaintField.Accessible = true; ((Paint)selectorWheelPaintField.Get(numberPicker)).Color = color; Field selectionDivider = numberPicker.Class.GetDeclaredField("mSelectionDivider"); selectionDivider.Accessible = true; selectionDivider.Set(numberPicker, numberPicker.Context.Resources.GetDrawable(Resource.Drawable.numberpicker_selection_divider)); ((EditText)child).SetTextColor(color); } catch (NoSuchFieldException e) { Log.Debug("setNumberPickerTextColor", e.Message); } catch (IllegalAccessException e) { Log.Debug("setNumberPickerTextColor", e.Message); } catch (Resources.NotFoundException e) { Log.Debug("setNumberPickerTextColor", e.Message); } } } numberPicker.Invalidate(); } catch { } }