protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (Control == null) { return; } if (e?.OldElement != null) { _helper.Clean(); } if (e?.NewElement == null) { return; } _materialButton = (MaterialButton)Element; _helper = new MaterialDrawableHelper(_materialButton, Control); _helper.UpdateDrawable(); Control.SetMinimumWidth((int)MaterialHelper.ConvertDpToPx(64)); Control.SetAllCaps(_materialButton != null && _materialButton.AllCaps); Control.SetMaxLines(1); SetTextColors(); }
public override void GetOutline(Android.Views.View view, Outline outline) { var inset = (int)MaterialHelper.ConvertDpToPx(6); var cornerRadius = (int)MaterialHelper.ConvertDpToPx(_cornerRadius); outline.SetRoundRect(inset, inset, view.Width - inset, view.Height - inset, cornerRadius); }
private void UpdateStrokeColor() { var borderColor = _materialCard.BorderColor.IsDefault ? _materialCard.BackgroundColor : _materialCard.BorderColor; var drawable = (GradientDrawable)Control.Background; drawable.SetStroke((int)MaterialHelper.ConvertDpToPx(1), borderColor.ToAndroid()); }
private void UpdateBorderWidth() { if (_button.ButtonType == MaterialButtonType.Text) { _borderWidth = 0; return; } _borderWidth = (int)MaterialHelper.ConvertDpToPx(_button.BorderWidth); }
private void SetControl() { if (Control == null) { return; } Control.Background = new ColorDrawable(Color.Transparent.ToAndroid()); Control.SetPadding(0, 0, 0, 0); Control.SetIncludeFontPadding(false); Control.SetMinimumHeight((int)MaterialHelper.ConvertDpToPx(20)); var layoutParams = new MarginLayoutParams(Control.LayoutParameters); layoutParams.SetMargins(0, 0, 0, 0); Control.LayoutParameters = layoutParams; }
private void SetControl() { if (Control == null) { return; } Control.Background = new ColorDrawable(Color.Transparent.ToAndroid()); Control.SetPadding(0, 0, 0, 0); Control.SetIncludeFontPadding(false); Control.SetMinimumHeight((int)MaterialHelper.ConvertDpToPx(20)); //// DEV HINT: This will be used for the future control `MaterialTextArea`. //// This removes the 'Next' button and shows a 'Done' button when the device's orientation is in landscape. //// This prevents the crash that is caused by a `java.lang.IllegalStateException'. //// Reported here https://github.com/xamarin/Xamarin.Forms/issues/4832. //this.Control.ImeOptions = Android.Views.InputMethods.ImeAction.Done; }
private StateListAnimator CreateStateListAnimator() { if (_button.ButtonType != MaterialButtonType.Elevated || !_aView.Enabled) { return(null); } var stateListAnimator = new StateListAnimator(); var objAnimTransZEnabled = ObjectAnimator.OfFloat(_aView, "translationZ", MaterialHelper.ConvertDpToPx(_button.Elevation.RestingElevation)) .SetDuration(100); objAnimTransZEnabled.StartDelay = 100; var objAnimElevationEnabled = ObjectAnimator.OfFloat(_aView, "elevation", MaterialHelper.ConvertDpToPx(_button.Elevation.RestingElevation)) .SetDuration(0); var objAnimTransZPressed = ObjectAnimator.OfFloat(_aView, "translationZ", MaterialHelper.ConvertDpToPx(_button.Elevation.PressedElevation)) .SetDuration(100); var objAnimElevationPressed = ObjectAnimator.OfFloat(_aView, "elevation", MaterialHelper.ConvertDpToPx(_button.Elevation.RestingElevation)) .SetDuration(0); var b = new AnimatorSet(); b.PlayTogether(objAnimTransZEnabled, objAnimElevationEnabled); b.SetTarget(_aView); var bb = new AnimatorSet(); bb.PlayTogether(objAnimTransZPressed, objAnimElevationPressed); bb.SetTarget(_aView); stateListAnimator.AddState(new[] { R.Attribute.StatePressed }, bb); stateListAnimator.AddState(new[] { R.Attribute.StateFocused, R.Attribute.StateEnabled }, bb); stateListAnimator.AddState(new[] { R.Attribute.StateEnabled }, b); stateListAnimator.AddState(new[] { R.Attribute.StateFocused }, bb); if (!(_aView is AppCompatImageButton)) { return(stateListAnimator); } _aView.OutlineProvider = new MaterialOutlineProvider(_button.CornerRadius); _aView.ClipToOutline = false; return(stateListAnimator); }
private void UpdateCornerRadius() { _cornerRadius = (int)MaterialHelper.ConvertDpToPx(_button.CornerRadius); }