示例#1
0
        private void CreateContainedButtonDrawable(bool elevated)
        {
            var normalStateDrawable   = this.CreateShapeDrawable(_cornerRadius, _borderWidth, _normalColor, _borderColor);
            var disabledStateDrawable = this.CreateShapeDrawable(_cornerRadius, _borderWidth, _disabledColor, _disabledBorderColor);

            if (Material.IsLollipop)
            {
                var rippleColor       = _normalColor.IsColorDark() ? Color.ParseColor("#52FFFFFF") : Color.ParseColor("#52000000");
                var rippleDrawable    = _withIcon ? MaterialHelper.GetDrawableCopyFromResource <RippleDrawable>(Resource.Drawable.drawable_ripple_with_icon) : MaterialHelper.GetDrawableCopyFromResource <RippleDrawable>(Resource.Drawable.drawable_ripple);
                var insetDrawable     = rippleDrawable.FindDrawableByLayerId(Resource.Id.inset_drawable) as InsetDrawable;
                var statelistDrawable = insetDrawable.Drawable as StateListDrawable;
                this.SetStates(statelistDrawable, normalStateDrawable, normalStateDrawable, disabledStateDrawable);

                rippleDrawable.SetColor(new Android.Content.Res.ColorStateList(new int[][]
                {
                    new int[] {}
                },
                                                                               new int[]
                {
                    rippleColor
                }));
                this.Control.Background        = rippleDrawable;
                this.Control.StateListAnimator = elevated ? AnimatorInflater.LoadStateListAnimator(this.Context, Resource.Animator.material_button_state_list_anim) : null;
            }

            else if (Material.IsJellyBean)
            {
                var stateListDrawable    = new StateListDrawable();
                var pressedStateDrawable = this.CreateShapeDrawable(_cornerRadius, _borderWidth, _pressedColor, _borderColor);
                this.SetStates(stateListDrawable, normalStateDrawable, pressedStateDrawable, disabledStateDrawable);
                this.Control.Background = stateListDrawable;
            }

            else
            {
                var insetDrawable        = MaterialHelper.GetDrawableCopyFromResource <InsetDrawable>(Resource.Drawable.drawable_selector);
                var stateListDrawable    = insetDrawable.Drawable as StateListDrawable;
                var pressedStateDrawable = this.CreateShapeDrawable(_cornerRadius, _borderWidth, _pressedColor, _borderColor);
                this.SetStates(stateListDrawable, normalStateDrawable, pressedStateDrawable, disabledStateDrawable);
                this.Control.Background = insetDrawable;
            }
        }
示例#2
0
        private void UpdateElevation()
        {
            if (!Material.IsLollipop)
            {
                return;
            }

            StateListAnimator stateListAnimator = null;

            if (_button.ButtonType == MaterialButtonType.Elevated && _aView.Enabled)
            {
                stateListAnimator = AnimatorInflater.LoadStateListAnimator(_aView.Context, Resource.Animator.material_button_state_list_anim);

                if (_aView is AppCompatImageButton)
                {
                    _aView.OutlineProvider = new MaterialOutlineProvider(_button.CornerRadius);
                    _aView.ClipToOutline   = false;
                }
            }

            _aView.StateListAnimator = stateListAnimator;
        }