public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.SearchMenu, menu); menu.TintIcons(); //// Associate searchable configuration with the SearchView var item = menu.FindItem(Resource.Id.ActionSearch); //var searchView = MenuItemCompat.GetActionView(item); //var a = item.ActionView; _searchView = new SearchView(this); MenuItemCompat.SetActionView(item, _searchView); item.SetShowAsAction(ShowAsAction.CollapseActionView | ShowAsAction.IfRoom); //item.SetActionView(_searchView); _searchView.FocusChange += SearchView_FocusChange; _searchView.SetOnQueryTextFocusChangeListener(this); //item.SetOnMenuItemClickListener(this); _searchView.QueryTextChange += (sender, e) => { _adapter.Filter.InvokeFilter(e.NewText); System.Diagnostics.Debug.WriteLine("Shown elements :" + _adapter.Count); }; _searchView.QueryTextSubmit += async(sender, e) => { var searchResult = await _storage.SearchRepositories(e.Query); _adapter.Replace(searchResult); e.Handled = true; }; return(true); }
private void InitToolbar(View view) { try { var toolbar = view.FindViewById <Toolbar>(Resource.Id.toolbar); GlobalContext.SetToolBar(toolbar, "", false); SearchBox = view.FindViewById <SearchView>(Resource.Id.browseSearchBox); SearchBox.SetIconifiedByDefault(false); if ((int)Build.VERSION.SdkInt < 23) { SearchBox.SetOnClickListener(this); SearchBox.SetOnSearchClickListener(this); SearchBox.SetOnQueryTextFocusChangeListener(this); } //Change text colors var editText = SearchBox.FindViewById <EditText>(Resource.Id.search_src_text); editText.SetHintTextColor(Color.Gray); editText.SetTextColor(Color.Black); Methods.SetFocusable(editText); editText.Touch += EditTextOnClick; ImageView searchViewIcon = (ImageView)SearchBox.FindViewById(Resource.Id.search_mag_icon); searchViewIcon.SetColorFilter(Color.Gray); } catch (Exception e) { Console.WriteLine(e); } }
public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.optionmenu, menu); menuitem = menu.FindItem(Resource.Id.action_search); var test = new SearchView(this); menuitem.SetActionView(test); var searchView = MenuItemCompat.GetActionView(menuitem); int searchImgId = Resources.GetIdentifier("android:id/search_button", null, null); ImageView v = (ImageView)searchView.FindViewById(searchImgId); //v.SetImageResource(Resource.Drawable.abc_ic_search); _searchView = searchView.JavaCast <SearchView>(); setSearchIcons(_searchView); _searchView.QueryTextChange += (s, e) => { var searchFor = e.NewText.ToLower(); if (!String.IsNullOrEmpty(searchFor)) { //Console.System.Diagnostics.Debug.WriteLine("searchFor:" + searchFor); // find matches, IndexOf means look for the input anywhere in the items // but it isn't case-sensitive by default! var matches = (from i in _approvalList where i.POID.ToLower().Contains(searchFor) select i).ToList(); //foreach (var match in matches) { //matchList.Add (match); //} ApprovalDetailList list = new ApprovalDetailList(this); matches.ForEach(model => list.Add(model)); _approvalListAdapter.SetData(list); _approvalListAdapter.NotifyDataSetChanged(); //if (_searchListView.Visibility == ViewStates.Gone && _searchView.Iconified == false) //{ // //_searchListView.Visibility = ViewStates.Visible; // _searchView.Iconified = true; //} } else { _approvalListAdapter.SetData(_approvalList); _approvalListAdapter.NotifyDataSetChanged(); } }; _searchView.SetOnQueryTextFocusChangeListener(new CustomSearchViewOnFocusChangeListenter(this)); _searchView.SetOnSearchClickListener(new CustomSearchviewclicklistener(rltitle)); _searchView.SetOnCloseListener(new CustomSearchViewOnCloseListenter(rltitle, _approvalListAdapter, _approvalList)); return(base.OnCreateOptionsMenu(menu)); }
void AddSearchToToolbar(string pageTitle) { if (GetToolbar() is Toolbar toolBar && toolBar.Menu?.FindItem(Resource.Id.ActionSearch)?.ActionView?.JavaCast <SearchView>().GetType() != typeof(SearchView)) { toolBar.Title = pageTitle; toolBar.InflateMenu(Resource.Menu.MainMenu); var menu = toolBar.Menu?.FindItem(Resource.Id.ActionSearch); menu.SetOnActionExpandListener(this); if (toolBar.Menu?.FindItem(Resource.Id.ActionSearch)?.ActionView?.JavaCast <SearchView>() is SearchView searchView) { SearchView = searchView; SearchView.SetOnQueryTextFocusChangeListener(this); SearchView.QueryTextChange += HandleQueryTextChange; SearchView.QueryTextSubmit += HandleQueryTextSubmit; SearchView.ImeOptions = (int)ImeAction.Done; SearchView.InputType = (int)InputTypes.TextVariationFilter; SearchView.MaxWidth = int.MaxValue; //Set to full width - http://stackoverflow.com/questions/31456102/searchview-doesnt-expand-full-width } } }