コード例 #1
0
		public static void SetTheme (ToggleButton toggleButton, FlatTheme theme, int padding, int size)
		{
			toggleButton.SetWidth(size * 5);
			toggleButton.SetHeight(size);

			//setTextOff("");
			//setTextOn("");

			int radius = size - 4;

			float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

			// creating unchecked-enabled state drawable
			var uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
			var uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, 5);

			var uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedEnabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			uncheckedEnabledBack.SetPadding(0, 0, size / 2 * 5, 0);

			Drawable[] d1 = {uncheckedEnabledBack, uncheckedEnabledFront};
			var uncheckedEnabled = new LayerDrawable(d1);

			// creating checked-enabled state drawable
			var checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
			var checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, 5);

			ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedEnabledBack.Paint.Color = theme.VeryLightAccentColor;
			checkedEnabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

			Drawable[] d2 = {checkedEnabledBack, checkedEnabledFront};
			LayerDrawable checkedEnabled = new LayerDrawable(d2);

			// creating unchecked-disabled state drawable
			ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedDisabledFrontCore.Paint.Color = Color.ParseColor("#d2d2d2");
			InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, 5);

			ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			uncheckedDisabledBack.SetPadding(0, 0, size / 2 * 5, 0);

			Drawable[] d3 = {uncheckedDisabledBack, uncheckedDisabledFront};
			LayerDrawable uncheckedDisabled = new LayerDrawable(d3);

			// creating checked-disabled state drawable
			ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedDisabledFrontCore.Paint.Color = theme.VeryLightAccentColor;
			InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, 5);

			ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			checkedDisabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

			Drawable[] d4 = {checkedDisabledBack, checkedDisabledFront};
			LayerDrawable checkedDisabled = new LayerDrawable(d4);

			toggleButton.SetPadding(0, padding, 0, padding);

			PaintDrawable paintDrawable = new PaintDrawable(theme.BackgroundColor);
			paintDrawable.SetIntrinsicHeight(size);
			paintDrawable.SetIntrinsicWidth(size);
			paintDrawable.SetPadding(size, 0, 0, 0);

			StateListDrawable states = new StateListDrawable();

			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(uncheckedEnabled, padding * 2));
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(checkedEnabled, padding * 2));
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(uncheckedDisabled, padding * 2));
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(checkedDisabled, padding * 2));

			toggleButton.SetBackgroundDrawable(states);

			toggleButton.SetTextSize(ComplexUnitType.Sp, 0);
		}
コード例 #2
0
		public static void SetTheme(EditText editText, FlatTheme theme, 
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, FlatUI.FlatTextAppearance textAppearance,
			int style, int radius, int padding, int border)
		{
			float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

			// creating normal state drawable
			var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalFront.SetPadding(padding, padding, padding, padding);

			var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalBack.SetPadding(border, border, border, border);

			if (style == 0) {             // flat
				normalFront.Paint.Color = Color.Transparent;
				normalBack.Paint.Color = theme.LightAccentColor;
				editText.SetTextColor(theme.VeryLightAccentColor);

			} else if (style == 1) {      // box
				normalFront.Paint.Color = Color.White;
				normalBack.Paint.Color = theme.LightAccentColor;
				editText.SetTextColor(theme.BackgroundColor);

			} else if (style == 2) {      // transparent
				normalFront.Paint.Color = Color.Transparent;
				normalBack.Paint.Color = Color.Transparent;
				editText.SetTextColor(theme.BackgroundColor);
			}

			Drawable[] d = {normalBack, normalFront};
			LayerDrawable normal = new LayerDrawable(d);

			editText.SetBackgroundDrawable(normal);

			editText.SetHintTextColor(theme.VeryLightAccentColor);

			if (textAppearance == FlatUI.FlatTextAppearance.Dark) editText.SetTextColor(theme.DarkAccentColor);
			else if (textAppearance == FlatUI.FlatTextAppearance.Light) editText.SetTextColor(theme.VeryLightAccentColor);

			var typeface = FlatUI.GetFont(editText.Context, fontFamily, fontWeight);
			if (typeface != null)
				editText.SetTypeface(typeface, TypefaceStyle.Normal);
		}
コード例 #3
0
		public static void SetTheme(Button button, FlatTheme theme, FlatUI.FlatTextAppearance textAppearance,
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, bool isFullFlat, int padding, int radius)
		{
			var bottom = 5;

			float[] outerR = {radius, radius, radius, radius, radius, radius, radius, radius};

			// creating normal state drawable
			var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalFront.Paint.Color = theme.LightAccentColor;
			normalFront.SetPadding(padding, padding, padding, padding);

			var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalBack.Paint.Color = theme.BackgroundColor;

			if (isFullFlat) 
				bottom = 0;

			normalBack.SetPadding(0, 0, 0, bottom);

			Drawable[] d = {normalBack, normalFront};
			var normal = new LayerDrawable(d);

			// creating pressed state drawable
			var pressedFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			pressedFront.Paint.Color = theme.BackgroundColor;

			var pressedBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			pressedBack.Paint.Color = theme.DarkAccentColor;

			if (!isFullFlat) 
				pressedBack.SetPadding(0, 0, 0, 3);

			Drawable[] d2 = {pressedBack, pressedFront};
			var pressed = new LayerDrawable(d2);

			// creating disabled state drawable
			var disabledFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			disabledFront.Paint.Color = theme.VeryLightAccentColor;

			var disabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			disabledBack.Paint.Color = theme.LightAccentColor;
			if (!isFullFlat) disabledBack.SetPadding(0, 0, 0, padding);

			Drawable[] d3 = {disabledBack, disabledFront};
			var disabled = new LayerDrawable(d3);

			var states = new StateListDrawable();

			states.AddState(new []{ Android.Resource.Attribute.StatePressed, Android.Resource.Attribute.StateEnabled }, pressed);
			states.AddState(new []{ Android.Resource.Attribute.StateFocused, Android.Resource.Attribute.StateEnabled }, pressed);
			states.AddState(new []{ Android.Resource.Attribute.StateEnabled }, normal);
			states.AddState(new []{-Android.Resource.Attribute.StateEnabled}, disabled);

			button.SetBackgroundDrawable (states);

			if (textAppearance == FlatUI.FlatTextAppearance.Dark) 
				button.SetTextColor(theme.DarkAccentColor);
			else if (textAppearance == FlatUI.FlatTextAppearance.Light) 
				button.SetTextColor(theme.VeryLightAccentColor);
			else 
				button.SetTextColor(Android.Graphics.Color.White);

			var typeface = FlatUI.GetFont(button.Context, fontFamily, fontWeight);
			if (typeface != null)
				button.SetTypeface(typeface, Android.Graphics.TypefaceStyle.Normal);
		}