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