Beispiel #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <RoundedView> e)
        {
            base.OnElementChanged(e);

            roundedView = Element as RoundedView;

            if (roundedView != null)
            {
                if (roundedView.UseGradient)
                {
                    var colors = new int[]
                    {
                        roundedView.StartColor.ToAndroid(),
                        roundedView.EndColor.ToAndroid()
                    };

                    gradient = new GradientDrawable(GradientDrawable.Orientation.LeftRight, colors);
                }
                else
                {
                    gradient = new GradientDrawable();
                    gradient.SetColor(roundedView.BackgroundColor.ToAndroid());
                }

                gradient.SetStroke(roundedView.BorderThickness, roundedView.BorderColor.ToAndroid());
                gradient.SetCornerRadius(AndroidUtils.ConvertDpToPixel(Context, roundedView.BorderRadius));

                Background = gradient;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var entry = Element as CustomEntry;

                var gradient = new GradientDrawable();
                var padding  = (int)AndroidUtils.ConvertDpToPixel(Context, 10);

                if (entry != null)
                {
                    gradient.SetStroke(entry.BorderThickness, entry.BorderColor.ToAndroid());
                    gradient.SetCornerRadius(AndroidUtils.ConvertDpToPixel(Context, entry.BorderRadius));
                    gradient.SetColor(entry.EntryBackgroundColor.ToAndroid());
                }

                if (!entry.DisplaySuggestions)
                {
                    Control.InputType = Android.Text.InputTypes.TextFlagNoSuggestions;
                }

                Control.Background = gradient;
                Control.SetPadding(padding, 0, padding, 0);
                Control.Gravity = Android.Views.GravityFlags.CenterVertical;

                switch (entry.HorizontalTextAlignment)
                {
                case Xamarin.Forms.TextAlignment.Start:
                    Control.TextAlignment = Android.Views.TextAlignment.TextStart;
                    break;

                case Xamarin.Forms.TextAlignment.Center:
                    Control.TextAlignment = Android.Views.TextAlignment.Center;
                    Control.Gravity       = Android.Views.GravityFlags.CenterHorizontal | Android.Views.GravityFlags.CenterVertical;
                    break;

                case Xamarin.Forms.TextAlignment.End:
                    Control.TextAlignment = Android.Views.TextAlignment.TextEnd;
                    break;

                default:
                    Control.TextAlignment = Android.Views.TextAlignment.TextStart;
                    break;
                }
            }
        }