Java Code Examples for android.support.v7.widget.SearchView#setIconifiedByDefault()

The following examples show how to use android.support.v7.widget.SearchView#setIconifiedByDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example 2
Source File: MusicContainerListActivity.java    From PlayMusicExporter with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.music_track_list, menu);

    // Finds the search item and create the search view
    MenuItem itemSearch = menu.findItem(R.id.action_search);
    mSearchView = (SearchView)MenuItemCompat.getActionView(itemSearch);

    if (mSearchView != null) {
        // Sets the search listener
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setIconifiedByDefault(true);

        // Hack to change the default placeholder
        EditText searchEditText = (EditText) mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
        searchEditText.setHint(R.string.search);
    }

    return true;
}
 
Example 3
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu_main, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to this Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchableInfo searchableInfo =
    searchManager.getSearchableInfo(getComponentName());

  SearchView searchView =
    (SearchView) menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example 4
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example 5
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example 6
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example 7
Source File: Food_RecyclerView_Main.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_actionview, menu);
    super.onCreateOptionsMenu(menu, inflater);

    final SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();
    if (search != null) {
        search.setIconifiedByDefault(true);
        search.setQuery(voice_query, true);
        // search.setQueryHint(voice_query);
        search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                String food;
                /*if (voice_query != "") {
                    food = voice_query;
                    search.setQueryHint(voice_query);
                    Log.d("searchvoice",voice_query);
                }
                else*/
                food = query;
                food = food.replace(" ", "");
                //String f_url = "https://api.nutritionix.com/v1_1/search/"+food+"?results=0%3A20&cal_min=0&cal_max=50000&fields=item_name%2Cbrand_name%2Citem_id%2Cbrand_id&appId=42e8cbe9&appKey=a4e373fe0f10ab1de40cffbffb9db544";
                String f_url = "https://api.nutritionix.com/v1_1/search/" + food + "?results=0%3A20&cal_min=0&cal_max=50000&fields=item_name%2Cbrand_name%2Citem_id%2Cbrand_id%2Citem_description%2Cnf_protein%2Cnf_calories%2Cnf_total_carbohydrate%2Cnf_total_fat&appId=42e8cbe9&appKey=a4e373fe0f10ab1de40cffbffb9db544";
                MyDownloadJsonAsyncTask downloadJson = new MyDownloadJsonAsyncTask(mRecyclerViewAdapter);
                Log.d("RahulMaddineni", f_url);
                downloadJson.execute(f_url);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return true;
            }
        });
    }
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 8
Source File: FriendSearchActivity.java    From CoolChat with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    layout_points = (LinearLayout) findViewById(R.id.layout_points);
    SearchView searchView = (SearchView) findViewById(R.id.search_view);
    //设置显示提交按钮
    searchView.setSubmitButtonEnabled(true);
    //一开始就处于显示SearchView的状态
    searchView.setIconifiedByDefault(false);
    //设置一开始就显示输入框
    searchView.setIconified(true);
    searchView.clearFocus();
    SearchView.SearchAutoComplete editText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchFriend(query.trim());
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!newText.isEmpty()) {
                searchFriend(newText);
            }
            return false;
        }
    });
}
 
Example 9
Source File: TransactionListFragment.java    From chuck with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.chuck_main, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setOnQueryTextListener(this);
    searchView.setIconifiedByDefault(true);
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 10
Source File: SearchActivity.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_search, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) menu.findItem(R.id.search).getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    //展开searchview
    mSearchView.setIconified(false);
    //显示默认框内标签
    mSearchView.setIconifiedByDefault(true);

    mToolbar.setTitle("");
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
            intent.putExtra("q", query);
            UIUtils.startActivity(intent);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return true;
}
 
Example 11
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 12
Source File: RecipeItemListActivity.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private void setUpSearchView(Menu menu) {
	MenuItem menuItem = menu.findItem(R.id.action_search);
	searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
	searchView.setIconifiedByDefault(false);
	SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
	MenuItemCompat.setOnActionExpandListener(menuItem, this);
	searchView.setOnSuggestionListener(this);

}
 
Example 13
Source File: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 14
Source File: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 15
Source File: ThreadFragment.java    From Ouroboros with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem goToBottomButton = menu.findItem(R.id.action_scroll_bottom);
    MenuItem goToTopButton = menu.findItem(R.id.action_scroll_top);
    MenuItem replyButton = menu.findItem(R.id.action_reply);
    MenuItem watchlistButton = menu.findItem(R.id.action_add_watchlist);
    MenuItem refreshButton = menu.findItem(R.id.action_refresh);
    MenuItem galleryButton = menu.findItem(R.id.action_gallery);
    MenuItem saveAllImagesButton = menu.findItem(R.id.action_save_all_images);
    MenuItem openExternalButton = menu.findItem(R.id.action_external_browser);
    MenuItem shareButton = menu.findItem(R.id.menu_item_share);
    MenuItem menuLayout = menu.findItem(R.id.action_menu_layout);

    MenuItem searchButton = menu.findItem(R.id.action_search);
    searchButton.setVisible(true);
    final SearchView searchView = (SearchView) searchButton.getActionView();
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            threadAdapter.setFilterQueryProvider(new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return infiniteDbHelper.searchThreadForString(constraint.toString(), resto);
                }
            });
            threadAdapter.getFilter().filter(newText);
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchButton, this);

    refreshButton.setVisible(true);
    goToBottomButton.setVisible(true);
    goToTopButton.setVisible(true);
    replyButton.setVisible(true);
    galleryButton.setVisible(true);
    saveAllImagesButton.setVisible(true);
    openExternalButton.setVisible(true);
    shareButton.setVisible(true);
    watchlistButton.setVisible(true);
    menuLayout.setVisible(true);

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 16
Source File: ContactsPickerActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.contact_list_menu, menu);

    mMenuStartGroupChat = menu.findItem(R.id.action_start_chat);
    updateStartGroupChatMenu();

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));

    if (mSearchView != null )
    {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setIconifiedByDefault(false);

        SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener()
        {
            public boolean onQueryTextChange(String newText)
            {
                mSearchString = newText;
                doFilterAsync(mSearchString);
                return true;
            }

            public boolean onQueryTextSubmit(String query)
            {
                mSearchString = query;
                doFilterAsync(mSearchString);

                return true;
            }
        };

        mSearchView.setOnQueryTextListener(queryTextListener);
    }



    return true;
}
 
Example 17
Source File: XposedAppManagerActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
            SearchManager searchManager =
                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

            selectAll=menu.findItem(R.id.select_all);
            setSelection=menu.findItem(R.id.setSelection);

            final SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

            searchEditText.setTextColor(getResources().getColor(R.color.white));
            searchView.setQueryHint("Search");

            // 将搜索按钮放到搜索输入框的外边
            searchView.setIconifiedByDefault(false);


            searchView.setSearchableInfo(
                    searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    refreshListByQuery(searchView.getQuery().toString());
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    refreshListByQuery("");
                    return false;
                }
            });

//            MenuItem menuItem=menu.add("恢复默认");
//            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
//            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem item) {
//                    if(mSelectedApplicationInfos==null){
//                        SnackBarUtil.show(toolbar,R.string.wait_until_loaded);
//                        return true;
//                    }
//                    for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
//                        app.isSelected=false;
//                    }
//                    mSelectedApplicationInfos.clear();
//                    mAppAdapter.notifyDataSetChanged();
//                    refreshTV();
//                    return true;
//                }
//            });
        }
        setSelection.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                showPopupMenu(toolbar);
                return true;
            }
        });
        refreshMenu(false);
        return true;
    }
 
Example 18
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}
 
Example 19
Source File: GlobalSearchFragment.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();

    inflater.inflate(R.menu.global_search_menu, menu);

    // Create a listener for search change
    final MenuItem search = menu.findItem(R.id.global_search_menu_search);
    final SearchView searchView = (SearchView) search.getActionView();
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);

    final SearchView.OnQueryTextListener queryTextListener
            = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            mSwipeRefreshLayout.setRefreshing(true);
            mEmptyView.setRefreshing(true);

            Message msg = Message.obtain();

            msg.obj = ClementineMessageFactory.buildGlobalSearch(query);
            App.ClementineConnection.mHandler.sendMessage(msg);

            hideSoftInput();

            // Set the actionbar title
            mActionBar.setTitle(getResources().getString(R.string.global_search_query, query));
            mActionBar.setSubtitle("/");

            // Query must be empty in order to collapse the search view.
            searchView.setQuery("", false);
            searchView.setIconified(true);

            // Remove currently present adapters
            mAdapters.clear();
            showList();

            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    searchView.setQueryHint(getString(R.string.global_search_search));

    EditText searchText = (EditText) searchView.findViewById(
            android.support.v7.appcompat.R.id.search_src_text);
    searchText.setHintTextColor(ContextCompat.getColor(getActivity(),
            R.color.searchview_edittext_hint));

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 20
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}