示例#1
0
 //public override void OnBackPressed()
 //{
 //   // this.Finish();
 //    MainActivity.Enter(this);
 //    base.OnBackPressed();
 //}
 public void OnFocusChange(View v, bool hasFocus)
 {
     if (v.Id == Resource.Id.search_keyword && hasFocus)
     {
         SearchInputActivity.Enter(category, this);
     }
 }
示例#2
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.searchResult);
            var app = ((InitApp)ApplicationContext);

            if (app != null)
            {
                app.addActivity(this);
            }
            tv_question    = FindViewById <TextView>(Resource.Id.tv_question);
            tv_news        = FindViewById <TextView>(Resource.Id.tv_news);
            tv_kb          = FindViewById <TextView>(Resource.Id.tv_kb);
            tv_blog        = FindViewById <TextView>(Resource.Id.tv_blog);
            search_keyword = FindViewById <SearchView>(Resource.Id.search_keyword);
            _recyclerView  = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
            swipeRefreshLayout.SetColorScheme(Resource.Color.primary);
            swipeRefreshLayout.Refreshing = false;
            StatusBarUtil.SetColorStatusBars(this);
            category   = Intent.GetStringExtra("category");
            keyword    = Intent.GetStringExtra("keyword");
            startQuery = Intent.GetBooleanExtra("startquery", false);


            initCategoryClick();      //初始化category单击事件
            initCategoryByCategory(); //初始化category 选中的状态
            toolbar.SetNavigationIcon(Resource.Drawable.back_24dp);
            toolbar.NavigationClick += (s, e) =>
            {
                ActivityCompat.FinishAfterTransition(this);
            };
            swipeRefreshLayout.Refresh += (s, e) =>
            {
                swipeRefreshLayout.PostDelayed(() => {
                    swipeRefreshLayout.Refreshing = false;
                }, 1000);
            };
            _recyclerView.SetLayoutManager(new Android.Support.V7.Widget.LinearLayoutManager(this));

            //search_keyword.SubmitButtonEnabled = true; //默认为false 不显示提交按钮,是否启用提交按钮
            search_keyword.OnActionViewExpanded(); //手动展开SearchView输入框,初始可以点击输入的状态
                                                   //search_keyword.SetIconifiedByDefault(false); //默认是为true 不显示输入框键盘,默认提交按钮不显示,该属性设置为false,则直接展开输入框弹出键盘
                                                   // search_keyword.RequestFocus(); //将控件设置成可获取焦点状态,默认是无法获取焦点的,只有设置成true,才能获取控件的点击事件
                                                   //search_keyword.Focusable = true;
            search_keyword.ClearFocus();
            search_keyword.Focusable = true;
            if (!string.IsNullOrEmpty(keyword))
            {
                search_keyword.QueryHint = keyword;
            }
            search_keyword.FocusChange += (s, e) =>
            {
                System.Diagnostics.Debug.Write(e.HasFocus);
                if (e.HasFocus)
                {
                    SearchInputActivity.Enter(category, this);
                }
            };

            search_keyword.SetOnQueryTextFocusChangeListener(this);
            search_keyword.QueryTextSubmit += async(s, e) =>
            {
                keyword = search_keyword.Query.Trim();
                if (keyword == null || keyword.Length == 0)
                {
                    return;
                }
                SearchHistoryShared.SetSearchHistory(keyword, this);
                swipeRefreshLayout.Refreshing = true;
                await listSearchService((list) => {
                    swipeRefreshLayout.PostDelayed(() => {
                        swipeRefreshLayout.Refreshing = false;
                    }, 1000);
                    searchList = list;
                    initRecycler();
                });
            };

            if (startQuery)
            {
                initCategoryByCategory();
                SearchHistoryShared.SetSearchHistory(keyword, this);
                if (!string.IsNullOrEmpty(keyword))
                {
                    swipeRefreshLayout.Refreshing = true;
                    await listSearchService((list) => {
                        swipeRefreshLayout.PostDelayed(() => {
                            swipeRefreshLayout.Refreshing = false;
                        }, 1000);
                        searchList = list;
                        initRecycler();
                    });
                }
            }
        }