protected override void OnElementChanged(ElementChangedEventArgs <Slider> e) { base.OnElementChanged(e); if (Control != null) { base.OnElementChanged(e); if (e.NewElement != null) { Control.ProgressDrawable.SetColorFilter( new PorterDuffColorFilter( Xamarin.Forms.Color.FromHex("#F50F76").ToAndroid(), PorterDuff.Mode.SrcIn)); // Set Progress bar Thumb color Control.Thumb.SetColorFilter( Xamarin.Forms.Color.FromHex("#F50F76").ToAndroid(), PorterDuff.Mode.SrcIn); //Change height GradientDrawable p = new GradientDrawable(); p.SetCornerRadius(20); p.SetColor(0x70b23f); ClipDrawable progress = new ClipDrawable(p, GravityFlags.Left, ClipDrawableOrientation.Horizontal); GradientDrawable background = new GradientDrawable(); background.SetColor(0xe0e0e0); background.SetCornerRadius(20); LayerDrawable pd = new LayerDrawable(new Drawable[] { background, progress }); Control.SetProgressDrawableTiled(pd); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Slider> e) { base.OnElementChanged(e); if (Control != null) { var customSlider = (CustomSlider)Element; if (customSlider.ThumbColor != Xamarin.Forms.Color.Transparent) { Control.Thumb.SetColorFilter(customSlider.ThumbColor.ToAndroid(), PorterDuff.Mode.SrcIn); } BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion >= BuildVersionCodes.M) { var trackCornerRadius = DpToPixels(customSlider.TrackCornerRadius); var trackHeight = DpToPixels(customSlider.TrackHeight); var progressGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LeftRight, new int[] { customSlider.ActiveTrackColor.ToAndroid(), customSlider.ActiveTrackColor.ToAndroid() }); progressGradientDrawable.SetCornerRadius(trackCornerRadius); var progress = new ClipDrawable(progressGradientDrawable, GravityFlags.Left, ClipDrawableOrientation.Horizontal); var background = new GradientDrawable(); background.SetColor(customSlider.InactiveTrackColor.ToAndroid()); background.SetCornerRadius(trackCornerRadius); var progressDrawable = new LayerDrawable(new Drawable[] { background, progress }); progressDrawable.SetLayerHeight(0, (int)trackHeight); progressDrawable.SetLayerHeight(1, (int)trackHeight); progressDrawable.SetLayerGravity(0, GravityFlags.CenterVertical); progressDrawable.SetLayerGravity(1, GravityFlags.CenterVertical); Control.ProgressDrawable = progressDrawable; } else { Element.MinimumTrackColor = customSlider.ActiveTrackColor; Control.SecondaryProgressTintList = ColorStateList.ValueOf(customSlider.InactiveTrackColor.ToAndroid()); Control.SecondaryProgressTintMode = PorterDuff.Mode.SrcIn; Control.SecondaryProgress = int.MaxValue; } Control.SetPadding(52, Control.PaddingTop, 52, Control.PaddingBottom); if (customSlider.UserInteractionEnabled) { Control.SplitTrack = true; Control.Thumb.Mutate().SetAlpha(255); } else { Control.SplitTrack = false; Control.Thumb.Mutate().SetAlpha(0); Control.Enabled = false; } } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Slider> e) { base.OnElementChanged(e); if (Control != null) { //convert details from CustomGradientSlider to android values var slider = Element as CustomGradientSlider; var startColor = slider.StartColor.ToAndroid(); var centerColor = slider.CenterColor.ToAndroid(); var endColor = slider.EndColor.ToAndroid(); var cornerRadiusInPx = ((float)slider.CornerRadius).DpToPixels(Context); var heightPx = ((float)slider.HeightRequest).DpToPixels(Context); //create minimum track var p = new GradientDrawable(GradientDrawable.Orientation.LeftRight, new int[] { startColor, centerColor, endColor }); p.SetCornerRadius(cornerRadiusInPx); var progress = new ClipDrawable(p, GravityFlags.Left, ClipDrawableOrientation.Horizontal); //create maximum track var background = new GradientDrawable(); background.SetColor(Element.MaximumTrackColor.ToAndroid()); background.SetCornerRadius(cornerRadiusInPx); var pd = new LayerDrawable(new Drawable[] { background, progress }); pd.SetLayerHeight(0, (int)heightPx); pd.SetLayerHeight(1, (int)heightPx); Control.ProgressDrawable = pd; } }
/* private void ShowCrashReport(UncaughtExceptionLogEntry uncaughtError) * { * var dialog = new CrashReportDialog(this); * dialog.OnClose += delegate { Resolve<IDatabase>().DeleteAll(typeof (UncaughtExceptionLogEntry)); }; * dialog.Show(uncaughtError); * }*/ private void SetupLoginButton() { loginButton = FindViewById <Button>(Resource.Id.login); loginButtonText = loginButton.Text; var layer = (LayerDrawable)loginButton.Background; progress = (ClipDrawable)layer.GetDrawable(1); }
public static void SetTheme(SeekBar seekBar, FlatTheme theme) { // setting thumb var thumb = new PaintDrawable(theme.DarkAccentColor); thumb.SetCornerRadius(15); thumb.SetIntrinsicWidth(30); thumb.SetIntrinsicHeight(30); seekBar.SetThumb(thumb); // progress var progress = new PaintDrawable(theme.BackgroundColor); progress.SetCornerRadius(10); progress.SetIntrinsicHeight(10); progress.SetIntrinsicWidth(5); progress.SetDither(true); var progressClip = new ClipDrawable(progress, GravityFlags.Left, ClipDrawableOrientation.Horizontal); // secondary progress var secondary = new PaintDrawable(theme.LightAccentColor); secondary.SetCornerRadius(10); secondary.SetIntrinsicHeight(10); var secondaryProgressClip = new ClipDrawable(secondary, GravityFlags.Left, ClipDrawableOrientation.Horizontal); // background PaintDrawable background = new PaintDrawable(theme.VeryLightAccentColor); background.SetCornerRadius(10); background.SetIntrinsicHeight(10); // applying drawable LayerDrawable ld = (LayerDrawable)seekBar.ProgressDrawable; ld.SetDrawableByLayerId(Android.Resource.Id.Background, background); ld.SetDrawableByLayerId(Android.Resource.Id.Progress, progressClip); ld.SetDrawableByLayerId(Android.Resource.Id.SecondaryProgress, secondaryProgressClip); }