protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            formControl = (Element as EntryUnderline);

            var editText = (EditText)Control;

            editText.Touch += (a, aa) =>
            {
                aa.Handled = false;
                var w  = editText.Width;
                var wl = editText.CompoundPaddingLeft;
                var wr = w - editText.CompoundPaddingRight;
                var x  = aa.Event.GetX();
                if (wr < x && aa.Event.Action == Android.Views.MotionEventActions.Down)
                {
                    formControl.IsPassword = !formControl.IsPassword;
                }
            };

            if (formControl.Icon != null)
            {
                var size = editText.TextSize;
                //var rightDrawable = formControl.IsPassword == true ? GetDrawable("view.png") : null;
                //editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(formControl.Icon)?.Target as Drawable, null, rightDrawable?.Target as Drawable, null);
                editText.CompoundDrawablePadding = 20;
                editText.Gravity = Android.Views.GravityFlags.Bottom;
                editText.Background.Mutate().SetColorFilter(formControl.EntryColor.ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop);
            }
        }
Пример #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null && Element != null)
            {
                Control.BorderStyle = UITextBorderStyle.None;

                formControl  = (Element as EntryUnderline);
                controlColor = formControl.EntryColor.ToCGColor();

                var ctrl = (UITextField)Control;
                ctrl.TextColor = formControl.EntryColor.ToUIColor();
                ctrl.TintColor = formControl.EntryColor.ToUIColor();

                var fontSize = ctrl.Font.PointSize;
                var s1       = fontSize + 2;

                if (formControl.Icon != null)
                {
                    if (formControl.Icon.IndexOf(".png", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        formControl.Icon = formControl.Icon + ".png";
                    }

                    var imgView = new UIImageView(new CGRect(0, 0, (fontSize), (fontSize)));
                    imgView.Image = ChangeImageColor(new UIImage(formControl.Icon), formControl.EntryColor.ToUIColor());
                    Resize(imgView, fontSize);

                    var paddingView = new UIView(new CGRect(0, 0, (fontSize + 4), (fontSize + 4)));
                    paddingView.AddSubview(imgView);
                    ctrl.LeftViewMode = UITextFieldViewMode.Always;
                    ctrl.LeftView     = paddingView;
                }
                //if (formControl.IsPassword)
                //{
                //    var imgView = new UIImageView(new CGRect(0, 0, (fontSize), (fontSize)));
                //    imgView.Image = ChangeImageColor(new UIImage("view.png"), formControl.EntryColor.ToUIColor());
                //    Resize(imgView, fontSize);

                //    var paddingView = new UIView(new CGRect(0, 0, (fontSize + 4), (fontSize + 4)));

                //    var btn = new UIButton(paddingView.Frame);
                //    btn.AddSubview(imgView);
                //    btn.TouchUpInside += (ee, aa) =>
                //    {
                //        formControl.IsPassword = !formControl.IsPassword;
                //    };
                //    paddingView.AddSubview(btn);
                //    ctrl.RightViewMode = UITextFieldViewMode.Always;
                //    ctrl.RightView = paddingView;
                //    ctrl.RightView.UserInteractionEnabled = true;
                //}
            }
        }