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
            {
            }
        }
Exemplo n.º 3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Alarm_NewAlarm, null, false);

            SetAlarm          = v.FindViewById <ImageView>(Resource.Id.imageView1);
            SetAlarmContainer = v.FindViewById <RelativeLayout>(Resource.Id.relativeLayout2);
            SetAlarmText      = v.FindViewById <TextView>(Resource.Id.textView2);
            AlarmHour         = v.FindViewById <NumberPicker>(Resource.Id.numberPicker1);
            AlarmMin          = v.FindViewById <NumberPicker>(Resource.Id.numberPicker2);
            Dots            = v.FindViewById <TextView>(Resource.Id.textView1);
            AlarmName       = v.FindViewById <EditText>(Resource.Id.editText1);
            RemindMe        = v.FindViewById <CheckBox>(Resource.Id.checkBox1);
            EarthquakeAlert = v.FindViewById <CheckBox>(Resource.Id.checkBox3);
            FireAlert       = v.FindViewById <CheckBox>(Resource.Id.checkBox2);

            AlarmMin.MaxValue = 59;
            AlarmMin.MinValue = 00;

            AlarmHour.MaxValue = 23;
            AlarmHour.MinValue = 00;

            if (FragmentShown == null)
            {
                AlarmHour.Value = System.DateTime.Now.Hour;
                AlarmMin.Value  = System.DateTime.Now.Minute + 1;
            }

            TextView Text = (TextView)AlarmHour.GetChildAt(0);

            SetAlarm.Touch          += SetAlarm_Touch;
            FragmentShown           += Alarm_NewAlarm_FragmentShown;
            RemindMe.Click          += RemindMe_Click;
            FireAlert.CheckedChange += FireAlert_CheckedChange;

            SetTypeface.Italic.SetTypeFace(Activity, SetAlarmText);
            SetTypeface.Normal.SetTypeFace(Activity, AlarmName);
            SetTypeface.Normal.SetTypeFace(Activity, RemindMe);
            SetTypeface.Normal.SetTypeFace(Activity, EarthquakeAlert);
            SetTypeface.Normal.SetTypeFace(Activity, FireAlert);

            return(v);
        }