/// <summary> /// Raises the <see cref="E:ElementChanged" /> event. /// </summary> /// <param name="e">The <see cref="ElementChangedEventArgs{Entry}"/> instance containing the event data.</param> protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (!((Control != null) & (e.NewElement != null))) { return; } if (!(e.NewElement is EnhancedEntry entryExt)) { return; } { Control.ImeOptions = getValueFromDescription(entryExt.ReturnKeyType); Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), Control.ImeOptions); _gradientDrawable = new GradientDrawable(); _gradientDrawable.SetShape(ShapeType.Rectangle); _gradientDrawable.SetColor(entryExt.BackgroundColor.ToAndroid()); _gradientDrawable.SetCornerRadius(entryExt.CornerRadius); _gradientDrawable.SetStroke((int)entryExt.BorderWidth, entryExt.BorderColor.ToAndroid()); Rect padding = new Rect { Left = entryExt.LeftPadding, Right = entryExt.RightPadding, Top = entryExt.TopBottomPadding / 2, Bottom = entryExt.TopBottomPadding / 2 }; _gradientDrawable.GetPadding(padding); e.NewElement.Focused += (sender, evt) => { _gradientDrawable.SetStroke( (int)entryExt.BorderWidth, entryExt.FocusBorderColor.ToAndroid()); }; e.NewElement.Unfocused += (sender, evt) => { _gradientDrawable.SetStroke((int)entryExt.BorderWidth, entryExt.BorderColor.ToAndroid()); }; if (entryExt.EntryHeight != -1) { Control.SetHeight((int)DpToPixels(_context, entryExt.EntryHeight)); } Control.SetBackground(_gradientDrawable); if (Control != null && !string.IsNullOrEmpty(PackageName) && !string.IsNullOrEmpty(entryExt.LeftIcon)) { int identifier = Context.Resources.GetIdentifier( entryExt.LeftIcon, "drawable", PackageName); if (identifier != 0) { Drawable drawable = ContextCompat.GetDrawable(_context, identifier); if (drawable != null) { Control.SetCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); Control.CompoundDrawablePadding = entryExt.PaddingLeftIcon; entryExt.IconDrawableColorChanged += (sender, args) => { foreach (Drawable d in Control.GetCompoundDrawables()) { if (args.IsValid) { d?.SetColorFilter(new PorterDuffColorFilter(args.Color.ToAndroid(), PorterDuff.Mode.SrcIn)); } else { d?.ClearColorFilter(); } } }; } } } Control.EditorAction += (sender, args) => { if (entryExt.NextEntry == null) { if (_context.GetSystemService(Context.InputMethodService) is InputMethodManager inputMethodManager && _context is Activity) { Activity activity = (Activity)_context; IBinder token = activity.CurrentFocus?.WindowToken; inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None); activity.Window.DecorView.ClearFocus(); } } entryExt.EntryActionFired(); }; } }