Exemplo n.º 1
0
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var textColor         = MaterialColors.GetEntryTextColor(element.TextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, element.TextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;
            textField.ActiveTextInputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;

            // BackgroundColor
            textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, element.TextColor);

            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
Exemplo n.º 2
0
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var adjustedTextColor = AdjustTextColor(element);

            var textColor         = MaterialColors.GetEntryTextColor(adjustedTextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, adjustedTextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;

            var inputController = textField.ActiveTextInputController;

            inputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;
            inputController.DisabledColor = placeHolderColors.InlineColor;

            var brush = element.Background;

            if (Brush.IsNullOrEmpty(brush))
            {
                // BackgroundColor
                textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, adjustedTextColor);
            }
            else
            {
                // Background
                if (textField is UITextField || textField is MultilineTextField)
                {
                    var backgroundImage = ((UIView)textField).GetBackgroundImage(brush);
                    textField.BackgroundSize = backgroundImage?.Size;
                    var color = backgroundImage != null?UIColor.FromPatternImage(backgroundImage) : UIColor.Clear;

                    textField.ActiveTextInputController.BorderFillColor = color;
                }
            }
            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
        void ResetTextColors(Color formsTextColor, Color formsPlaceHolderColor)
        {
            _formsPlaceholderColor = formsPlaceHolderColor;
            _formsTextColor        = formsTextColor;

            var underlineColors   = MaterialColors.GetUnderlineColor(_formsPlaceholderColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(_formsPlaceholderColor, _formsTextColor);

            _placeholderColorsList       = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);
            _placeholderDefaultColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.DefaultColor);
            _underlineColorsList         = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);
            var textColor = MaterialColors.GetEntryTextColor(formsTextColor).ToArgb();

            EditText.SetTextColor(new ColorStateList(s_colorStates, new[] { textColor, textColor }));
        }
        void ResetTextColors(Color formsTextColor, Color formsPlaceHolderColor)
        {
            _formsPlaceholderColor = formsPlaceHolderColor;
            _formsTextColor        = formsTextColor;

            var underlineColors   = MaterialColors.GetUnderlineColor(_formsTextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(_formsPlaceholderColor, _formsTextColor);

            // I realize these are the same but I have to set it to a difference instance
            // otherwise when focused it won't change to the color I want it to and it'll just think
            // I'm not actually changing anything
            _unfocusedUnderlineColorsList = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);
            _focusedUnderlineColorsList   = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);

            _focusedFilledColorList  = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.FloatingColor, placeHolderColors.FloatingColor);
            _unfocusedEmptyColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);

            var textColor = MaterialColors.GetEntryTextColor(formsTextColor).ToArgb();

            EditText.SetTextColor(new ColorStateList(s_colorStates, new[] { textColor, textColor }));
        }