Advertisement
aldakur

SetNumberPickerTextColorAndSize

May 20th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. public static bool SetNumberPickerTextColorAndSize(NumberPicker numberPicker, Color color, ComplexUnitType complexUnitType, float textSize, TypefaceStyle style)
  2.     {
  3.         int count = numberPicker.ChildCount;
  4.         for (int i = 0; i < count; i++)
  5.         {
  6.             View child = numberPicker.GetChildAt(i);
  7.             if (child.GetType() == typeof(EditText))
  8.             {
  9.                 try
  10.                 {
  11.                     Field selectorWheelPaintField = numberPicker.Class
  12.                                                                 .GetDeclaredField("mSelectorWheelPaint");
  13.                     selectorWheelPaintField.Accessible = true;
  14.  
  15.                     EditText editText = (EditText) child;
  16.                     editText.SetTextSize(complexUnitType, textSize);
  17.                     editText.SetTypeface(editText.Typeface, style);
  18.                     editText.SetTextColor(color);
  19.  
  20.                     Paint paint = (Paint) selectorWheelPaintField.Get(numberPicker);
  21.                     paint.TextSize =  TypedValue.ApplyDimension(complexUnitType, textSize, numberPicker.Resources.DisplayMetrics);
  22.                     paint.Color = color;
  23.                     paint.SetTypeface(editText.Typeface);
  24.  
  25.                     numberPicker.Invalidate();
  26.                     return true;
  27.                 }
  28.                 catch (NoSuchFieldException e)
  29.                 {
  30.                     Log.Warn("setNumberPickerTextColor", e);
  31.                 }
  32.                 catch (IllegalAccessException e)
  33.                 {
  34.                     Log.Warn("setNumberPickerTextColor", e);
  35.                 }
  36.                 catch (IllegalArgumentException e)
  37.                 {
  38.                     Log.Warn("setNumberPickerTextColor", e);
  39.                 }
  40.             }
  41.         }
  42.         return false;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement