当前位置: 首页>>代码示例>>C#>>正文


C# ToggleButton.SetWidth方法代码示例

本文整理汇总了C#中ToggleButton.SetWidth方法的典型用法代码示例。如果您正苦于以下问题:C# ToggleButton.SetWidth方法的具体用法?C# ToggleButton.SetWidth怎么用?C# ToggleButton.SetWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ToggleButton的用法示例。


在下文中一共展示了ToggleButton.SetWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetTheme

		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);
		}
开发者ID:patelh18,项目名称:FlatUI.Xamarin.Android,代码行数:82,代码来源:FlatToggleButton.cs


注:本文中的ToggleButton.SetWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。