public static AColor ToAndroid(this Color self, Color defaultColor) { if (self == Color.Default) return defaultColor.ToAndroid(); return ToAndroid(self); }
public void UpdateTextColor(TextView control, Color color) { if (color == _currentTextColor) return; _currentTextColor = color; if (color.IsDefault) control.SetTextColor(_defaultTextColors); else { // Set the new enabled state color, preserving the default disabled state color int defaultDisabledColor = _defaultTextColors.GetColorForState(s_colorStates[1], color.ToAndroid()); control.SetTextColor(new ColorStateList(s_colorStates, new[] { color.ToAndroid().ToArgb(), defaultDisabledColor })); } }
public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) { var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), // is this correct? ag.Shader.TileMode.Clamp); var paint = new ag.Paint(); paint.SetShader(shader); return new BrushObject { Paint = paint }; // TODO: initial matrix }
public object Create(Color color) { var result = new ag.Paint { Color = color.ToAndroid(), }; result.SetStyle(ag.Paint.Style.Fill); return result; }
void UpdateBorderColor() { if (_disposed) { return; } Color borderColor = Element.BorderColor; _backgroundDrawable.SetStroke(3, borderColor.IsDefault ? AColor.White : borderColor.ToAndroid()); }
public object Create(Color color, float thickness) { var paint = new ag.Paint { Color = color.ToAndroid(), StrokeWidth = thickness, StrokeCap = ag.Paint.Cap.Square, StrokeMiter = 10f }; return paint; }
protected virtual ColorStateList GetItemTextColorStates() { if (IsDisposed) { return(null); } if (_originalTabTextColors == null) { _originalTabTextColors = (IsBottomTabPlacement) ? _bottomNavigationView.ItemTextColor : _tabLayout.TabTextColors; } Color barItemColor = BarItemColor; Color barTextColor = Element.BarTextColor; Color barSelectedItemColor = BarSelectedItemColor; if (barItemColor.IsDefault && barTextColor.IsDefault && barSelectedItemColor.IsDefault) { return(_originalTabTextColors); } if (_newTabTextColors != null) { return(_newTabTextColors); } int checkedColor; int defaultColor; if (!barTextColor.IsDefault) { checkedColor = barTextColor.ToAndroid().ToArgb(); defaultColor = checkedColor; } else { defaultColor = barItemColor.ToAndroid().ToArgb(); if (barItemColor.IsDefault && _originalTabTextColors != null) { defaultColor = _originalTabTextColors.DefaultColor; } checkedColor = defaultColor; if (!barSelectedItemColor.IsDefault) { checkedColor = barSelectedItemColor.ToAndroid().ToArgb(); } } _newTabTextColors = GetColorStateList(defaultColor, checkedColor); return(_newTabTextColors); }
protected override void UpdateBackgroundColor() { Color colorToSet = Element.Color; if (_backgroundDrawable == null) { _backgroundDrawable = new GradientDrawable(); } if (colorToSet != Color.Default) { _backgroundDrawable.SetColor(colorToSet.ToAndroid()); } else { _backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent)); } this.SetBackground(_backgroundDrawable); }
protected override void UpdateBackgroundColor() { Color colorToSet = Element.Color; if (colorToSet == Color.Default) { colorToSet = Element.BackgroundColor; } SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent)); }
void SetTabColors () { for (int i = 0; i < Element.Children.Count; ++i) { Page page = Element.Children[i]; Color tabColor = BottomBarPageExtensions.GetTabColor (page); if (tabColor != Color.Transparent) { _bottomBar.MapColorForTab (i, tabColor.ToAndroid ()); } } }
void UpdateBackgroundColor() { if (_disposed) { return; } Color bgColor = Element.BackgroundColor; _backgroundDrawable.SetColor(bgColor.IsDefault ? AColor.White : bgColor.ToAndroid()); }
public void SetTheme(Color color) { if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M) { Device.BeginInvokeOnMainThread(() => { var currentWindow = GetCurrentWindow(); currentWindow.DecorView.SystemUiVisibility = 0; currentWindow.SetStatusBarColor(color.ToAndroid()); }); } }
public void SetStatusBarColor(string color) { Color barColor = Color.FromHex(color); //(Android.App.Application.Context as FormsAppCompatActivity).Window.SetStatusBarColor(barColor.ToAndroid()); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var c = MainActivity.context as FormsAppCompatActivity; c?.RunOnUiThread(() => c.Window.SetStatusBarColor(barColor.ToAndroid())); } }
public void ChangeStatusBarColor(Color color) { MainActivity main = ((MainActivity)CrossCurrentActivity.Current.Activity); // Set the status bar color. if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { main.Window.ClearFlags(WindowManagerFlags.TranslucentStatus); main.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); main.Window.SetStatusBarColor(color.ToAndroid()); //main.Window.SetStatusBarColor(new Android.Graphics.Color(30, 138, 118)); } }
protected override void OnStart() { base.OnStart(); var window = Window; window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); window.ClearFlags(WindowManagerFlags.TranslucentStatus); Color color = (Color)Xamarin.Forms.Application.Current.Resources["Primary"]; window.SetStatusBarColor(color.ToAndroid()); }
public object Create(Color color, float thickness) { var paint = new ag.Paint { Color = color.ToAndroid(), StrokeWidth = thickness, StrokeCap = ag.Paint.Cap.Square, StrokeMiter = 10f }; return(paint); }
public void ChangeStatusBarColor(Color color) { var activity = (FormsAppCompatActivity)Material.Context; var isColorDark = color.ToAndroid().IsColorDark(); activity.SetStatusBarColor(color.ToAndroid()); if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { if (!isColorDark) { activity.Window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar; } else { activity.Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible; } } }
public static ICharSequence GetTitle(Color titleColor, string title) { if (titleColor == null) { return(new Java.Lang.String(title)); } var spannableTitle = new SpannableString(title ?? ""); spannableTitle.SetSpan(new ForegroundColorSpan(titleColor.ToAndroid()), 0, spannableTitle.Length(), SpanTypes.ExclusiveExclusive); return(spannableTitle); }
protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color) { var menuView = bottomView.GetChildAt(0) as BottomNavigationMenuView; var oldBackground = bottomView.Background; var colorDrawable = oldBackground as ColorDrawable; var colorChangeRevealDrawable = oldBackground as ColorChangeRevealDrawable; AColor lastColor = colorChangeRevealDrawable?.EndColor ?? colorDrawable?.Color ?? Color.Default.ToAndroid(); AColor newColor; if (color == Color.Default) { newColor = Color.White.ToAndroid(); } else { newColor = color.ToAndroid(); } if (menuView == null) { if (colorDrawable != null && lastColor == newColor) { return; } if (lastColor != newColor || colorDrawable == null) { bottomView.SetBackground(new ColorDrawable(newColor)); } } else { if (colorChangeRevealDrawable != null && lastColor == newColor) { return; } var index = ((IShellItemController)_shellItem).GetItems().IndexOf(_shellItem.CurrentItem); var menu = bottomView.Menu; index = Math.Min(index, menu.Size() - 1); var child = menuView.GetChildAt(index); if (child == null) { return; } var touchPoint = new Point(child.Left + (child.Right - child.Left) / 2, child.Top + (child.Bottom - child.Top) / 2); bottomView.SetBackground(new ColorChangeRevealDrawable(lastColor, newColor, touchPoint)); } }
protected void UpdateBackgroundColor() { if (Element == null) { return; } Color backgroundColor = Element.BackgroundColor; if (backgroundColor.IsDefault) { if (SupportBackgroundTintList != null) { Context context = Context; int id = GlobalResource.Attribute.ButtonTint; unchecked { using (var value = new TypedValue()) { try { Resources.Theme theme = context.Theme; if (theme != null && theme.ResolveAttribute(id, value, true)) #pragma warning disable 618 { SupportBackgroundTintList = Resources.GetColorStateList(value.Data); } #pragma warning restore 618 else { SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } } catch (Exception ex) { Internals.Log.Warning("Xamarin.Forms.Platform.Android.ButtonRenderer", "Could not retrieve button background resource: {0}", ex); SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } } } } } else { int intColor = backgroundColor.ToAndroid().ToArgb(); int disableColor = backgroundColor.MultiplyAlpha(0.5).ToAndroid().ToArgb(); SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { intColor, disableColor }); } }
void UpdateBackgroundColor() { Color modalBkgndColor = _modal.BackgroundColor; if (modalBkgndColor.IsDefault) { _backgroundView.SetWindowBackground(); } else { _backgroundView.SetBackgroundColor(modalBkgndColor.ToAndroid()); } }
public void SetStatusBarColor(Color color) { // The SetStatusBarcolor is new since API 21 if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var androidColor = color.ToAndroid(); CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(androidColor); } else { // Here you will just have to set your color in styles.xml file as above. } }
public void SetColor(Color color) { var window = MainActivity.CurrentActivity.Window; window.SetStatusBarColor(color.ToAndroid()); // For light colors, switch status bar icons to dark // BTW, Color.Default has a -1 luminosity. Which is hard to deal with, since it should be 0 to 1. So we do a Math.Abs here if (Math.Abs(color.Luminosity) > 0.6) { window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar; } }
protected virtual void SetColors(Toolbar toolbar, IShellToolbarTracker toolbarTracker, Color foreground, Color background, Color title) { var titleArgb = title.ToAndroid(ShellRenderer.DefaultTitleColor).ToArgb(); if (_titleTextColor != titleArgb) { toolbar.SetTitleTextColor(titleArgb); _titleTextColor = titleArgb; } var newColor = background.ToAndroid(ShellRenderer.DefaultBackgroundColor); if (!(toolbar.Background is ColorDrawable cd) || cd.Color != newColor) { using (var colorDrawable = new ColorDrawable(background.ToAndroid(ShellRenderer.DefaultBackgroundColor))) toolbar.SetBackground(colorDrawable); } var newTintColor = foreground.IsDefault ? ShellRenderer.DefaultForegroundColor : foreground; if (toolbarTracker.TintColor != newTintColor) toolbarTracker.TintColor = newTintColor; }
private void SetTint() { ImageView image = this.Control as ImageView; if (image == null) { return; } Color newColor = Shared.TintEffect.GetTintColor(this.Element); image.SetColorFilter(newColor.ToAndroid()); }
protected override void UpdateBackgroundColor() { Color colorToSet = Element.Color; if (colorToSet == Color.Default) colorToSet = Element.BackgroundColor; if (_backgroundDrawable != null) { if (colorToSet != Color.Default) _backgroundDrawable.SetColor(colorToSet.ToAndroid()); else _backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent)); this.SetBackground(_backgroundDrawable); } else { if (colorToSet == Color.Default) colorToSet = Element.BackgroundColor; SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent)); } }
void UpdateColor() { Color color = Element.Color; if (!color.IsDefault) { Control.IndeterminateDrawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn); } else { Control.IndeterminateDrawable.ClearColorFilter(); } }
public void SetColor(Color color) { var progress = color.IsDefault ? DefaultColor : color.ToAndroid(); if (Forms.IsLollipopOrNewer) { IndeterminateTintList = ColorStateList.ValueOf(progress); } else { (Indeterminate ? IndeterminateDrawable : ProgressDrawable).SetColorFilter(color.ToAndroid(), FilterMode.SrcIn); } }
internal static void ApplySeekBarColors(this ASeekBar seekBar, Color progressColor, Color backgroundColor, Color thumbColor) { seekBar.ApplyProgressBarColors(progressColor, backgroundColor); if (Forms.IsLollipopOrNewer) { if (thumbColor.IsDefault) { // reset everything to defaults seekBar.ThumbTintList = seekBar.ProgressTintList; } else { // handle the case where the thumb is set var thumb = thumbColor.ToAndroid(); seekBar.ThumbTintList = ColorStateList.ValueOf(thumb); } } else { seekBar.Thumb.SetColorFilter(thumbColor.ToAndroid(), FilterMode.SrcIn); } }
protected virtual void UpdateBackgroundColor(Color color = null) { if (Element == null) { return; } Color backgroundColor = color ?? Element.BackgroundColor; if (backgroundColor != null) { SetBackgroundColor(backgroundColor.ToAndroid()); } }
protected virtual ColorStateList GetItemIconTintColorState() { if (IsDisposed) { return(null); } if (IsBottomTabPlacement) { if (_orignalTabIconColors == null) { _orignalTabIconColors = _bottomNavigationView.ItemIconTintList; } } // this ensures that existing behavior doesn't change else if (!IsBottomTabPlacement && BarSelectedItemColor.IsDefault && BarItemColor.IsDefault) { return(null); } Color barItemColor = BarItemColor; Color barSelectedItemColor = BarSelectedItemColor; if (barItemColor.IsDefault && barSelectedItemColor.IsDefault) { return(_orignalTabIconColors); } if (_newTabIconColors != null) { return(_newTabIconColors); } int defaultColor = barItemColor.ToAndroid().ToArgb(); if (barItemColor.IsDefault && _orignalTabIconColors != null) { defaultColor = _orignalTabIconColors.DefaultColor; } int checkedColor = defaultColor; if (!barSelectedItemColor.IsDefault) { checkedColor = barSelectedItemColor.ToAndroid().ToArgb(); } _newTabIconColors = GetColorStateList(defaultColor, checkedColor); return(_newTabIconColors); }
private GradientDrawable GetBorderDrawable(Color borderColor, Color backgroundColor, float borderWidth, int borderRadius) { GradientDrawable gd = new GradientDrawable(); borderWidth = borderWidth > 0 ? borderWidth : 0; borderRadius = borderRadius > 0 ? borderRadius : 0; borderColor = borderColor != Color.Default ? borderColor : Color.Transparent; backgroundColor = backgroundColor != Color.Default ? backgroundColor : Color.Transparent; gd.SetColor(ColorStateList.ValueOf(backgroundColor.ToAndroid())); gd.SetStroke((int)borderWidth, ColorStateList.ValueOf(borderColor.ToAndroid())); gd.SetCornerRadius((float)borderRadius); return(gd); }
void ISetStatusBarColor.SetStatusBarColor(Color color) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var androidColor = color.ToAndroid(); //Just use the plugin CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(androidColor); } else { // Here you will just have to set your // color in styles.xml file as shown below. } }
public static ICharSequence GetTitle(Color titleColor, string title) { if (titleColor == null) { return(new Java.Lang.String(title)); } var spannableTitle = new SpannableString(title ?? ""); #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962 spannableTitle.SetSpan(new ForegroundColorSpan(titleColor.ToAndroid()), 0, spannableTitle.Length(), SpanTypes.ExclusiveExclusive); #pragma warning restore CA1416 return(spannableTitle); }
void UpdateBarBackgroundColor() { if (_disposed || _tabLayout == null) { return; } Color tintColor = Element.BarBackgroundColor; if (Forms.IsLollipopOrNewer) { if (tintColor.IsDefault) { _tabLayout.BackgroundTintMode = null; } else { _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src; _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid()); } } else { if (tintColor.IsDefault && _backgroundDrawable != null) { _tabLayout.SetBackground(_backgroundDrawable); } else if (!tintColor.IsDefault) { if (_backgroundDrawable == null) { _backgroundDrawable = _tabLayout.Background; } _tabLayout.SetBackgroundColor(tintColor.ToAndroid()); } } }
public void SetColor(Pen widget, Color color) { widget.ToAndroid().Color = color.ToAndroid(); }