protected override TextInputLayout CreateNativeControl() { var textInputLayout = new TextInputLayout(Context); var autoComplete = new AppCompatAutoCompleteTextView(Context) { BackgroundTintList = ColorStateList.ValueOf(GetPlaceholderColor()), Text = Element?.Text, Hint = Element?.Placeholder, }; GradientDrawable gd = new GradientDrawable(); gd.SetColor(global::Android.Graphics.Color.Transparent); autoComplete.SetBackground(gd); if (Element != null) { autoComplete.SetHintTextColor(Element.PlaceholderColor.ToAndroid()); autoComplete.SetTextColor(Element.TextColor.ToAndroid()); } textInputLayout.AddView(autoComplete); return(textInputLayout); }
protected virtual void LoadView(SearchHandler searchHandler) { var query = searchHandler.Query; var placeholder = searchHandler.Placeholder; LP lp; var context = Context; _cardView = new CardView(context); using (lp = new LayoutParams(LP.MatchParent, LP.MatchParent)) _cardView.LayoutParameters = lp; var linearLayout = new LinearLayout(context); using (lp = new LP(LP.MatchParent, LP.MatchParent)) linearLayout.LayoutParameters = lp; linearLayout.Orientation = Orientation.Horizontal; _cardView.AddView(linearLayout); int padding = (int)context.ToPixels(8); _searchButton = CreateImageButton(context, searchHandler, SearchHandler.QueryIconProperty, Resource.Drawable.abc_ic_search_api_material, padding, 0); lp = new LinearLayout.LayoutParams(0, LP.MatchParent) { Gravity = GravityFlags.Fill, Weight = 1 }; _textBlock = new AppCompatAutoCompleteTextView(context) { LayoutParameters = lp, Text = query, Hint = placeholder, ImeOptions = ImeAction.Done }; lp.Dispose(); _textBlock.Enabled = searchHandler.IsSearchEnabled; _textBlock.SetBackground(null); _textBlock.SetPadding(padding, 0, padding, 0); _textBlock.SetSingleLine(true); _textBlock.Threshold = 1; _textBlock.Adapter = new ShellSearchViewAdapter(SearchHandler, _shellContext); _textBlock.ItemClick += OnTextBlockItemClicked; _textBlock.SetDropDownBackgroundDrawable(new ClipDrawableWrapper(_textBlock.DropDownBackground)); // A note on accessibility. The _textBlocks hint is what android defaults to reading in the screen // reader. Therefor we do not need to set something else. _clearButton = CreateImageButton(context, searchHandler, SearchHandler.ClearIconProperty, Resource.Drawable.abc_ic_clear_material, 0, padding); _clearPlaceholderButton = CreateImageButton(context, searchHandler, SearchHandler.ClearPlaceholderIconProperty, -1, 0, padding); linearLayout.AddView(_searchButton); linearLayout.AddView(_textBlock); linearLayout.AddView(_clearButton); linearLayout.AddView(_clearPlaceholderButton); UpdateClearButtonState(); // hook all events down here to avoid getting events while doing setup searchHandler.PropertyChanged += OnSearchHandlerPropertyChanged; _textBlock.AddTextChangedListener(this); _textBlock.SetOnEditorActionListener(this); _clearButton.Click += OnClearButtonClicked; _clearPlaceholderButton.Click += OnClearPlaceholderButtonClicked; _searchButton.Click += OnSearchButtonClicked; AddView(_cardView); linearLayout.Dispose(); }