예제 #1
0
        public static void UpdateBackground(Border border, Android.Views.View view)
        {
            var strokeThickness = border.StrokeThickness;
            var context = view.Context;

            // create stroke drawable
            GradientDrawable strokeDrawable = null;

            // if thickness exists, set stroke drawable stroke and radius
            if(strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0) {
                strokeDrawable = new GradientDrawable ();
                strokeDrawable.SetColor (border.BackgroundColor.ToAndroid ());

                // choose thickest margin
                // the content is padded so it will look like the margin is with the given thickness
                strokeDrawable.SetStroke ((int)context.ToPixels (strokeThickness.ThickestSide()), border.Stroke.ToAndroid ());
                strokeDrawable.SetCornerRadius ((float)border.CornerRadius);
            }

            // create background drawable
            var backgroundDrawable = new GradientDrawable ();

            // set background drawable color based on Border's background color
            backgroundDrawable.SetColor (border.BackgroundColor.ToAndroid ());
            backgroundDrawable.SetCornerRadius((float)border.CornerRadius);

            if (strokeDrawable != null) {
                // if stroke drawable exists, create a layer drawable containing both stroke and background drawables
                var ld = new LayerDrawable (new Drawable[] { strokeDrawable, backgroundDrawable });
                ld.SetLayerInset (1, (int)context.ToPixels (strokeThickness.Left), (int)context.ToPixels (strokeThickness.Top), (int)context.ToPixels (strokeThickness.Right), (int)context.ToPixels (strokeThickness.Bottom));
                view.SetBackgroundDrawable (ld);
            } else {
                view.SetBackgroundDrawable (backgroundDrawable);
            }

            // set Android.View's padding to take into account the stroke thickiness
            view.SetPadding (
                (int)context.ToPixels (strokeThickness.Left + border.Padding.Left),
                (int)context.ToPixels (strokeThickness.Top + border.Padding.Top),
                (int)context.ToPixels (strokeThickness.Right + border.Padding.Right),
                (int)context.ToPixels (strokeThickness.Bottom + border.Padding.Bottom));
        }
        private void UpdateColors()
        {
            var button = Element as ShadowButton;

            var normal = new Android.Graphics.Drawables.GradientDrawable ();
            normal.SetColor (button.BackgroundColor.ToAndroid ());
            normal.SetStroke ((int)button.BorderWidth, button.BorderColor.ToAndroid ());
            normal.SetCornerRadius (button.BorderRadius);
            var shadow = new Android.Graphics.Drawables.GradientDrawable ();
            shadow.SetColor (button.ShadowColor.ToAndroid ());
            shadow.SetStroke ((int)button.BorderWidth, button.ShadowColor.ToAndroid ());
            shadow.SetCornerRadius (button.BorderRadius);

            _normal = new Android.Graphics.Drawables.LayerDrawable (
                new Drawable [] { shadow, normal }
            );

            var density = 3;

            _normal.SetLayerInset (1, 0, 0, 0, 2 * density);

            _pressed = new Android.Graphics.Drawables.GradientDrawable ();

            var highlight = Context.ObtainStyledAttributes (new int [] {
                Android.Resource.Attribute.ColorActivatedHighlight
            }).GetColor(0, Android.Graphics.Color.Gray);
            _pressed.SetColor (highlight);
            _pressed.SetStroke ((int)button.BorderWidth, button.BorderColor.ToAndroid ());
            _pressed.SetCornerRadius (button.BorderRadius);

            var sld = new StateListDrawable ();
            sld.AddState (new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
            sld.AddState (new int[] {}, _normal );

            Control.SetPaddingRelative (0, 0, 2, 0);
            Control.SetBackgroundDrawable (sld);
        }
    private Drawable CreateDrawable (int color)
    {
      var ovalShape = new OvalShape ();
      var shapeDrawable = new ShapeDrawable (ovalShape);
      shapeDrawable.Paint.Color = new Color (color);
      if (hasShadow && !HasLollipopApi) {
        var shadowDrawable = Resources.GetDrawable (size == FabSize.Normal ? 
          Resource.Drawable.fab_shadow :
          Resource.Drawable.fab_shadow_mini);

        var layerDrawable = new LayerDrawable (new Drawable[]{ shadowDrawable, shapeDrawable });
        layerDrawable.SetLayerInset (1, shadowSize, shadowSize, shadowSize, shadowSize);
        return layerDrawable;
      } else {
        return shapeDrawable;
      }
    }
예제 #4
0
		public static void SetActionBarTheme(Activity context, FlatTheme theme, bool dark)
		{
			var color1 = theme.LightAccentColor;
			var color2 = theme.BackgroundColor;

			if (dark) 
			{
				color1 = theme.BackgroundColor;
				color2 = theme.DarkAccentColor;
			}

			var front = new PaintDrawable(color1);
			var bottom = new PaintDrawable(color2);
			var d = new Drawable[] { bottom, front};
			var drawable = new LayerDrawable(d);
			drawable.SetLayerInset(1, 0, 0, 0, 3);

			var actionBar = context.ActionBar;
			actionBar.SetBackgroundDrawable(drawable);

			// invalidating action bar
			actionBar.Title = actionBar.Title;
		}