示例#1
0
        protected override MaterialFormsTextInputLayout CreateNativeControl()
        {
            LayoutInflater inflater = LayoutInflater.FromContext(Context);
            var            view     = inflater.Inflate(Resource.Layout.TextInputLayoutFilledBox, null);

            _textInputLayout   = (MaterialFormsTextInputLayout)view;
            _textInputEditText = _textInputLayout.FindViewById <MaterialFormsEditText>(Resource.Id.materialformsedittext);

            return(_textInputLayout);
        }
		protected override MaterialFormsTextInputLayout CreateNativeControl()
		{
			LayoutInflater inflater = LayoutInflater.FromContext(Context);
			var view = inflater.Inflate(Resource.Layout.TextInputLayoutFilledBox, null);
			_textInputLayout = (MaterialFormsTextInputLayout)view;
			_textInputEditText = _textInputLayout.FindViewById<MaterialFormsEditText>(Resource.Id.materialformsedittext);
			_textInputEditText.FocusChange += TextInputEditTextFocusChange;
			_textInputLayout.Hint = Element.Placeholder;

			return _textInputLayout;
		}
示例#3
0
        void IVisualElementRenderer.SetElement(VisualElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            if (!(element is Entry))
            {
                throw new ArgumentException($"{nameof(element)} must be of type {nameof(Entry)}");
            }

            VisualElement oldElement = Entry;

            Entry = (Entry)element;

            Performance.Start(out string reference);

            if (oldElement != null)
            {
                oldElement.PropertyChanged      -= OnElementPropertyChanged;
                oldElement.FocusChangeRequested -= OnFocusChangeRequested;
            }

            if (oldElement == null)
            {
                _textInputEditText = new MaterialFormsEditText(Context);
                AddView(_textInputEditText);

                _textInputEditText.FocusChange += _textInputEditText_FocusChange;
                Hint = Entry.Placeholder;

                _textInputEditText.AddTextChangedListener(this);
                _textInputEditText.SetOnEditorActionListener(this);
                _textInputEditText.OnKeyboardBackPressed += OnKeyboardBackPressed;
                _textInputEditText.SelectionChanged      += SelectionChanged;

                var useLegacyColorManagement = Entry.UseLegacyColorManagement();

                _textColorSwitcher = new TextColorSwitcher(_textInputEditText.TextColors, useLegacyColorManagement);
                _hintColorSwitcher = new TextColorSwitcher(_textInputEditText.HintTextColors, useLegacyColorManagement);
            }

            // When we set the control text, it triggers the SelectionChanged event, which updates CursorPosition and SelectionLength;
            // These one-time-use variables will let us initialize a CursorPosition and SelectionLength via ctor/xaml/etc.
            _cursorPositionChangePending  = Element.IsSet(Entry.CursorPositionProperty);
            _selectionLengthChangePending = Element.IsSet(Entry.SelectionLengthProperty);


            Hint = Entry.Placeholder;
            _textInputEditText.Text = Entry.Text;
            UpdateInputType();
            UpdateColor();
            UpdateAlignment();
            UpdateFont();
            UpdatePlaceholderColor(true);
            UpdateMaxLength();
            UpdateImeOptions();
            UpdateReturnType();
            UpdateBackgroundColor();

            if (_cursorPositionChangePending || _selectionLengthChangePending)
            {
                UpdateCursorSelection();
            }

            element.PropertyChanged += OnElementPropertyChanged;
            if (_tracker == null)
            {
                _tracker = new VisualElementTracker(this);
            }
            element.SendViewInitialized(this);
            EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
            Performance.Stop(reference);
            ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, element));

            element.FocusChangeRequested += OnFocusChangeRequested;
        }