private void updateBackground() { var color = Color.ParseColor(Item.Color); if (Item.Source == CalendarItemSource.Calendar) { color.A = (byte)(color.A * 0.25); } secondBackgroundLayer?.SetColor(color); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { //Control.SetBackgroundResource(Resource.Layout.rounded_shape); var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(60f); gradientDrawable.SetStroke(5, Android.Graphics.Color.Black); gradientDrawable.SetColor(Android.Graphics.Color.GhostWhite); Control.SetBackground(gradientDrawable); Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); try { if (Control != null) { GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); this.Control.SetBackground(gd); this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions); Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.LightSlateGray)); } } catch (Exception ex) { } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { CustomEntry control = e.NewElement as CustomEntry; var entry = (TextView)Control; entry.SetTextSize(Android.Util.ComplexUnitType.Dip, control.Size); //==================================================== GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); this.Control.SetBackgroundDrawable(gd); this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions); Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.LightGray)); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { EditText nativeEditText = (EditText)Control; ShapeDrawable shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape()); shape.Paint.Color = Xamarin.Forms.Color.Black.ToAndroid(); shape.Paint.SetStyle(Paint.Style.Stroke); nativeEditText.Background = shape; GradientDrawable gd = new GradientDrawable(); gd.SetColor(Android.Graphics.Color.Rgb(247, 246, 246)); gd.SetCornerRadius(50f); gd.SetStroke(0, Android.Graphics.Color.LightGray); nativeEditText.SetBackground(gd); Control.SetPadding(40, 40, 40, 40); } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (Control != null) { SetAlignment(); var density = Math.Max(1, Resources.DisplayMetrics.Density); var button = e.NewElement as BorderedButton; var mode = MeasureSpec.GetMode(button.BorderRadius); var borderRadius = button.BorderRadius * density; var borderWidth = button.BorderWidth * density; // Create a drawable for the button's normal state _normal = new GradientDrawable(); _normal.SetColor(button.NormalBackgroundColor.ToAndroid()); _normal.SetStroke((int)borderWidth, button.BorderColor.ToAndroid()); _normal.SetCornerRadius(borderRadius); // Create a drawable for the button's pressed state _pressed = new GradientDrawable(); _pressed.SetColor(button.PressedBackgroundColor.ToAndroid()); _pressed.SetStroke((int)borderWidth, button.BorderColor.ToAndroid()); _pressed.SetCornerRadius(borderRadius); // Add the drawables to a state list and assign the state list to the button var sld = new StateListDrawable(); sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed); sld.AddState(new int[] { }, _normal); Control.SetBackground(sld); Control.SetTextColor(new ColorStateList( new int[][] { new int [] { Android.Resource.Attribute.StatePressed }, new int [] {} }, new int[] { button.PressedTextColor.ToAndroid(), button.NormalTextColor.ToAndroid() } )); } }
/// <summary> /// Drawables the state changed. /// </summary> protected override void DrawableStateChanged() { base.DrawableStateChanged(); RoundedCornerView rcv = ((RoundedCornerView)Element); var shape = new GradientDrawable(); if (rcv.MakeCircle) { shape.SetCornerRadius(Math.Min(Width, Height) / 2); } else { shape.SetCornerRadius((float)rcv.RoundedCornerRadius); } shape.SetColor(rcv.FillColor.ToAndroid()); shape.SetStroke((int)rcv.BorderWidth, (((RoundedCornerView)Element)).BorderColor.ToAndroid()); this.SetBackground(shape); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { base.OnElementChanged(e); var pickerControl = Control; if (pickerControl == null) { return; } pickerControl.TextSize = 14; var gd = new GradientDrawable(); gd.SetColor(Android.Graphics.Color.Transparent); #pragma warning disable 618 pickerControl.SetBackgroundDrawable(gd); #pragma warning restore 618 pickerControl.SetRawInputType(InputTypes.TextFlagNoSuggestions); pickerControl.SetHintTextColor(ColorStateList.ValueOf(Android.Graphics.Color.White)); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { base.OnElementChanged(e); //LINHA if (Control != null) { GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); this.Control.SetBackgroundDrawable(gd); Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.Rgb(229, 238, 199))); } //BORDA if (e.OldElement == null) { this.Control.Background = this.Resources.GetDrawable(Resource.Drawable.noBorderEditText); } }
public MapSwitch(Context context) : base(context) { textView = new TextView(context); textView.Gravity = Android.Views.GravityFlags.CenterVertical; textView.SetPadding(10, 0, 0, 0); AddView(textView); textView.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, 1); customSwitch = new CustomSwitch(context); AddView(customSwitch); customSwitch.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, 1); background = new GradientDrawable(); background.SetCornerRadius(5); background.SetColor(Color.Argb(130, 0, 0, 0).ToArgb()); Background = background; }
private GradientDrawable CreateShapeDrawable(float cornerRadius, int borderWidth, Color backgroundColor, Color borderColor) { GradientDrawable shapeDrawable = null; if (_button.ButtonType != MaterialButtonType.Text) { shapeDrawable = _withIcon ? MaterialHelper.GetDrawableCopyFromResource <GradientDrawable>(Resource.Drawable.drawable_shape_with_icon) : MaterialHelper.GetDrawableCopyFromResource <GradientDrawable>(Resource.Drawable.drawable_shape); } else { shapeDrawable = MaterialHelper.GetDrawableCopyFromResource <GradientDrawable>(Resource.Drawable.drawable_shape_text); } shapeDrawable.SetCornerRadius(cornerRadius); shapeDrawable.SetColor(backgroundColor); shapeDrawable.SetStroke(borderWidth, borderColor); return(shapeDrawable); }
protected override void OnAttached() { var control = Control as EditText; if (control == null) { return; } var effect = (EntryEffect)Element.Effects.FirstOrDefault(e => e is EntryEffect); if (effect != null) { GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); control.SetBackground(gd); control.SetRawInputType(InputTypes.TextFlagNoSuggestions); control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.White)); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement != null) { return; } var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(60f); gradientDrawable.SetStroke(5, Android.Graphics.Color.LightGray); gradientDrawable.SetColor(Android.Graphics.Color.LightGray); gradientDrawable.SetAlpha(100); Control.SetBackground(gradientDrawable); Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (Control != null) { var searchView = Control as SearchView; var gradient = new GradientDrawable(); gradient.SetColor(Android.Graphics.Color.White); int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null); var icon = searchView.FindViewById(searchIconId); icon.LayoutParameters = new LinearLayout.LayoutParams(0, 0); int searchPlateId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null); Android.Views.View searchPlateView = searchView.FindViewById(searchPlateId); searchPlateView.SetBackground(gradient); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var gd = new GradientDrawable(); gd.SetCornerRadius(2); gd.SetColor(global::Android.Graphics.Color.White); var padTop = 20; var padBottom = 20; var padLeft = 20; var padRight = 20; Control.SetPadding(padLeft, padTop, padRight, padBottom); Control.SetBackground(gd); } }
public void SetBackground(Color color, Brush brush) { if (Background is GradientDrawable gradientDrawable) { GradientDrawable backgroundDrawable = gradientDrawable.GetConstantState().NewDrawable() as GradientDrawable; if (!Brush.IsNullOrEmpty(brush)) { backgroundDrawable.UpdateBackground(brush, Height, Width); } else { _backgroudColor = color.IsDefault ? AColor.Transparent : color.ToAndroid(); backgroundDrawable.SetColor(_backgroudColor); } Background = backgroundDrawable; } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var view = (CustomEntry)Element; var outline = new GradientDrawable(); outline.SetShape(ShapeType.Rectangle); outline.SetColor(view.BackgroundColor.ToAndroid()); outline.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); if (view.IsCurvedCornersEnabled) { outline.SetCornerRadius(15f); } Control.SetPadding(20, Control.PaddingTop, 20, Control.PaddingTop); Control.SetBackground(outline); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var gradient = new GradientDrawable(); var roundedEntry = Element as RoundedEntry; var padding = (int)Utils.ConvertDpToPixel(Context, 10); if (roundedEntry != null) { gradient.SetStroke(roundedEntry.BorderThickness, roundedEntry.BorderColor.ToAndroid()); gradient.SetCornerRadius(Utils.ConvertDpToPixel(Context, roundedEntry.BorderRadius)); gradient.SetColor(roundedEntry.EntryBackgroundColor.ToAndroid()); SetReturnType(roundedEntry); // Editor Action is called when the return button is pressed Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) => { if (roundedEntry.ReturnType != ReturnType.Next) { roundedEntry.Unfocus(); } // Call all the methods attached to base_entry event handler Completed roundedEntry.InvokeCompleted(); }; } if (!roundedEntry.DisplaySuggestions) { Control.InputType = Android.Text.InputTypes.TextFlagNoSuggestions; } Control.Background = gradient; Control.SetPadding(padding, padding, padding, padding); } }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { base.OnElementChanged(e); if ((Control != null) && (e.OldElement == null)) { MyEditorRenderer myEditorRenderer = (MyEditorRenderer)Element; var gradientDrawable = new GradientDrawable(); gradientDrawable.SetColor(myEditorRenderer.StaticColor.ToAndroid()); switch (myEditorRenderer.TypeBorder) { case TypeBorder.All: gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80, 80, 80, 80, 80 }); break; case TypeBorder.Left: gradientDrawable.SetCornerRadii(new float[] { 80, 80, 0, 0, 0, 0, 80, 80 }); break; case TypeBorder.Right: gradientDrawable.SetCornerRadii(new float[] { 0, 0, 80, 80, 80, 80, 0, 0 }); break; case TypeBorder.Down: gradientDrawable.SetCornerRadii(new float[] { 0, 0, 0, 0, 80, 80, 80, 80 }); break; case TypeBorder.Up: gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80, 0, 0, 0, 0 }); break; } Control.SetPadding(40, 20, 40, 20); Control.SetBackground(gradientDrawable); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } element = (entry)this.Element; element.TextChanged += Element_TextChanged; var editText = this.Control; if (!string.IsNullOrEmpty(element.Image)) { //switch (element.ImageAlignment) //{ // case ImageAlignment.Left: // editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null); // break; // case ImageAlignment.Right: // editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null); // break; //} } //editText.CompoundDrawablePadding = 0; //Control.Background.SetColorFilter(Android.Graphics.Color.Transparent, PorterDuff.Mode.SrcAtop); Control.SetPadding(0, 0, 0, 0); editText.CompoundDrawablePadding = 0; editText.SetPadding(0, 0, 0, 0); var gradientDrawable = new GradientDrawable(); // gradientDrawable.SetCornerRadius(15f); // gradientDrawable.SetStroke(3, Android.Graphics.Color.White); gradientDrawable.SetColor(Android.Graphics.Color.Transparent); Control.SetBackground(gradientDrawable); }
protected void ChangeBackgroundPattern() { var element = Element as CalendarButton; if (element?.BackgroundPattern == null || Control.Width == 0) { return; } var d = new List <Drawable>(); for (var i = 0; i < element.BackgroundPattern.Pattern.Count; i++) { var bp = element.BackgroundPattern.Pattern[i]; d.Add(!string.IsNullOrEmpty(bp.Text) ? new TextDrawable(bp.Color.ToAndroid()) { Pattern = bp } : new ColorDrawable(bp.Color.ToAndroid())); } var drawable = new GradientDrawable(); drawable.SetShape(ShapeType.Rectangle); var borderWidth = (int)Math.Ceiling(element.BorderWidth); drawable.SetStroke(borderWidth > 0 ? borderWidth + 1 : borderWidth, element.TintBorderColor.ToAndroid()); drawable.SetColor(Color.Transparent); d.Add(drawable); var layer = new LayerDrawable(d.ToArray()); for (var i = 0; i < element.BackgroundPattern.Pattern.Count; i++) { var l = (int)Math.Ceiling(Control.Width * element.BackgroundPattern.GetLeft(i)); var t = (int)Math.Ceiling(Control.Height * element.BackgroundPattern.GetTop(i)); var r = (int)Math.Ceiling(Control.Width * (1 - element.BackgroundPattern.Pattern[i].WidthPercent)) - l; var b = (int)Math.Ceiling(Control.Height * (1 - element.BackgroundPattern.Pattern[i].HightPercent)) - t; layer.SetLayerInset(i, l, t, r, b); } layer.SetLayerInset(d.Count - 1, 0, 0, 0, 0); Control.SetBackground(layer); }
InsetDrawable GetCheckedDrawable() { var rect = new GradientDrawable(); rect.SetShape(ShapeType.Rectangle); rect.SetColor(GetColorList()); //rect.SetStroke(0, _tintColor); rect.SetStroke(1, TintColor); rect.SetCornerRadius(0); //var line = new GradientDrawable(); //line.SetShape(ShapeType.Rectangle); //line.SetStroke(_strokeWidth, _tintColor); return(new InsetDrawable(rect, 0)); //return new LayerDrawable(new Drawable[] { // new InsetDrawable(rect, 0), // //new InsetDrawable(line, -_strokeWidth, -_strokeWidth, -_strokeWidth, 0) //}); }
void SetBorder(WLabel view) { if (view.BorderRadius > 0 || view.BorderWidth > 0) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); _gradientBackground.SetColor(view.BackgroundColor.ToAndroid()); // Thickness of the stroke line _gradientBackground.SetStroke(FDroidUtils.Dp(view.BorderWidth), view.BorderColor.ToAndroid()); // Radius for the curves _gradientBackground.SetCornerRadius(FDroidUtils.Dp(view.BorderRadius)); // set the background of the label Control.SetBackgroundColor(Color.Transparent.ToAndroid()); Control.SetBackground(_gradientBackground); } }
protected override void OnElementChanged(ElementChangedEventArgs <Frame> e) { base.OnElementChanged(e); var origFrame = e.NewElement as CustomElementFrame; if (origFrame != null) { GradientDrawable gi = new GradientDrawable(); _gi = gi; gi.SetStroke(origFrame.BorderThickness, origFrame.OutlineColor.ToAndroid()); gi.SetColor(origFrame.BackgroundColor.ToAndroid()); gi.SetCornerRadius(origFrame.CornerRadius); #pragma warning disable CS0618 // Type or member is obsolete SetBackgroundDrawable(gi); #pragma warning restore CS0618 // Type or member is obsolete } }
public static void InitializeFrom(this View nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } var background = new GradientDrawable(); background.SetColor(formsControl.BackgroundColor.ToAndroid()); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { nativeControl.Background = background; } nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { base.OnElementChanged(e); if (Control != null) { if (e.OldElement == null) { //Control.SetBackgroundResource(Resource.Layout.rounded_shape); var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(60f); // gradientDrawable.SetStroke(5, Android.Graphics.Color.DeepPink); gradientDrawable.SetColor(Android.Graphics.Color.Transparent); Control.SetBackground(gradientDrawable); Control.SetPadding(40, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { string fontFamily = e.NewElement?.FontFamily; if (!string.IsNullOrEmpty(fontFamily)) { var label = (TextView)Control; // for example Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, fontFamily + ".otf"); label.Typeface = font; } GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); this.Control.SetBackgroundDrawable(gd); this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions); //Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.White)); } }
protected override void OnAttached() { try { var control = Control ?? Container as Android.Views.View; var effect = (FrameEffect)Element.Effects.FirstOrDefault(e => e is FrameEffect); if (effect != null) { control.SetBackgroundResource(Resource.Drawable.FrameRenderValue); GradientDrawable drawable = (GradientDrawable)control.Background; drawable.SetColor(Android.Graphics.Color.ParseColor("#F0F0F0")); } } catch (Exception ex) { Debug.WriteLine("Cannot set property on attached control. Error: {0}", ex.Message); } }
Drawable CreateShape(ShapeType type, int strokeWidth, int cornerRadius, Xamarin.Forms.Color?fillColor, Xamarin.Forms.Color?strokeColor) { GradientDrawable shape = new GradientDrawable(); shape.SetShape(type); if (fillColor != null) { shape.SetColor(fillColor?.ToAndroid() ?? Xamarin.Forms.Color.Transparent.ToAndroid()); } if (strokeColor != null) { shape.SetStroke(strokeWidth, strokeColor?.ToAndroid() ?? Xamarin.Forms.Color.Transparent.ToAndroid()); } shape.SetCornerRadius(cornerRadius); return(shape); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(60f); gradientDrawable.SetStroke(5, Android.Graphics.Color.Argb(100, 30, 144, 255)); gradientDrawable.SetColor(Android.Graphics.Color.LightGray); Control.SetBackground(gradientDrawable); Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); //IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(CustomEntry)); //IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); // my_cursor is the xml file name which we defined above //JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor); } }