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);
            }
        }
Пример #2
0
        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));
        }