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); } }
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); } }