コード例 #1
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);
            }
        }
コード例 #2
0
        public static void SetTheme(TextView textView, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int textColor, int backgroundColor,
                                    int customBackgroundColor, int cornerRadius)
        {
            if (backgroundColor != -1)
            {
                var bgColor = theme.DarkAccentColor;

                if (backgroundColor == 0)
                {
                    bgColor = theme.DarkAccentColor;
                }
                else if (backgroundColor == 1)
                {
                    bgColor = theme.BackgroundColor;
                }
                else if (backgroundColor == 2)
                {
                    bgColor = theme.LightAccentColor;
                }
                else if (backgroundColor == 3)
                {
                    bgColor = theme.VeryLightAccentColor;
                }

                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.SetColor(bgColor);
                gradientDrawable.SetCornerRadius(cornerRadius);
                textView.SetBackgroundDrawable(gradientDrawable);
            }
            else if (customBackgroundColor != -1)
            {
                var bgColor = theme.DarkAccentColor;

                if (customBackgroundColor == 0)
                {
                    bgColor = theme.DarkAccentColor;
                }
                else if (customBackgroundColor == 1)
                {
                    bgColor = theme.BackgroundColor;
                }
                else if (customBackgroundColor == 2)
                {
                    bgColor = theme.LightAccentColor;
                }
                else if (customBackgroundColor == 3)
                {
                    bgColor = theme.VeryLightAccentColor;
                }

                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.SetColor(bgColor);
                gradientDrawable.SetCornerRadius(cornerRadius);
                textView.SetBackgroundDrawable(gradientDrawable);
            }

            var txtColor = theme.VeryLightAccentColor;

            if (textColor == 0)
            {
                txtColor = theme.DarkAccentColor;
            }
            if (textColor == 1)
            {
                txtColor = theme.BackgroundColor;
            }
            if (textColor == 2)
            {
                txtColor = theme.LightAccentColor;
            }
            if (textColor == 3)
            {
                txtColor = theme.VeryLightAccentColor;
            }

            textView.SetTextColor(txtColor);

            var typeface = FlatUI.GetFont(textView.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                textView.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
コード例 #3
0
        public static void SetTheme(CheckBox checkBox, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int radius, int size, int border)
        {
            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedEnabled = new GradientDrawable();

            uncheckedEnabled.SetCornerRadius(radius);
            uncheckedEnabled.SetSize(size, size);
            uncheckedEnabled.SetColor(Color.Transparent);
            uncheckedEnabled.SetStroke(border, theme.LightAccentColor);

            // creating checked-enabled state drawable
            GradientDrawable checkedOutside = new GradientDrawable();

            checkedOutside.SetCornerRadius(radius);
            checkedOutside.SetSize(size, size);
            checkedOutside.SetColor(Color.Transparent);
            checkedOutside.SetStroke(border, theme.LightAccentColor);

            PaintDrawable checkedCore = new PaintDrawable(theme.LightAccentColor);

            checkedCore.SetCornerRadius(radius);
            checkedCore.SetIntrinsicHeight(size);
            checkedCore.SetIntrinsicWidth(size);
            InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedEnabledDrawable = { checkedOutside, checkedInside };
            LayerDrawable checkedEnabled         = new LayerDrawable(checkedEnabledDrawable);

            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedDisabled = new GradientDrawable();

            uncheckedDisabled.SetCornerRadius(radius);
            uncheckedDisabled.SetSize(size, size);
            uncheckedDisabled.SetColor(Color.Transparent);
            uncheckedDisabled.SetStroke(border, theme.VeryLightAccentColor);

            // creating checked-disabled state drawable
            GradientDrawable checkedOutsideDisabled = new GradientDrawable();

            checkedOutsideDisabled.SetCornerRadius(radius);
            checkedOutsideDisabled.SetSize(size, size);
            checkedOutsideDisabled.SetColor(Color.Transparent);
            checkedOutsideDisabled.SetStroke(border, theme.VeryLightAccentColor);

            PaintDrawable checkedCoreDisabled = new PaintDrawable(theme.VeryLightAccentColor);

            checkedCoreDisabled.SetCornerRadius(radius);
            checkedCoreDisabled.SetIntrinsicHeight(size);
            checkedCoreDisabled.SetIntrinsicWidth(size);
            InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
            LayerDrawable checkedDisabled         = new LayerDrawable(checkedDisabledDrawable);


            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, uncheckedEnabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, checkedEnabled);
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, uncheckedDisabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, checkedDisabled);
            checkBox.SetButtonDrawable(states);

            // setting padding for avoiding text to be appear on icon
            checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
            checkBox.SetTextColor(theme.LightAccentColor);

            var typeface = FlatUI.GetFont(checkBox.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                checkBox.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
コード例 #4
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);
            }
        }