Java Code Examples for android.support.v7.widget.SearchView#setSearchableInfo()
The following examples show how to use
android.support.v7.widget.SearchView#setSearchableInfo() .
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: MainActivity.java From ActivityDiary with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchMenuItem = menu.findItem(R.id.action_filter); searchView = (SearchView) searchMenuItem.getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnCloseListener(this); searchView.setOnQueryTextListener(this); // setOnSuggestionListener -> for selection of a suggestion // setSuggestionsAdapter searchView.setOnSearchClickListener(v -> setSearchMode(true)); return true; }
Example 2
Source File: MainActivity.java From VCL-Android with Apache License 2.0 | 6 votes |
/** Create menu from XML */ @TargetApi(Build.VERSION_CODES.FROYO) @Override public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu; /* Note: on Android 3.0+ with an action bar this method * is called while the view is created. This can happen * any time after onCreate. */ MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.media_library, menu); if (AndroidUtil.isFroyoOrLater()) { SearchManager searchManager = (SearchManager) VLCApplication.getAppContext().getSystemService(Context.SEARCH_SERVICE); mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search)); mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); mSearchView.setQueryHint(getString(R.string.search_hint)); SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null); searchSuggestionsAdapter.setFilterQueryProvider(this); mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter); } else menu.findItem(R.id.ml_menu_search).setVisible(false); return super.onCreateOptionsMenu(menu); }
Example 3
Source File: EarthquakeMainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
@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 4
Source File: PhotosListActivity.java From photoviewer with Apache License 2.0 | 6 votes |
private void setUpSearchMenu(Menu menu) { // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { mPhotoListPresenter.searchByTitle(newText); return true; } }); searchView.setOnCloseListener(() -> { mPhotoListPresenter.searchByTitle(null); return false; }); }
Example 5
Source File: MainActivity.java From InifiniteRecyclerView with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the options menu from XML MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); MenuItem searchMenuItem = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) searchMenuItem.getActionView(); searchView.setSearchableInfo(searchManager. getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(this); MenuItemCompat.setOnActionExpandListener(searchMenuItem, this); return true; }
Example 6
Source File: MainActivity.java From Moticons with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_main, menu); searchItem = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); moticoinsItem = menu.findItem(R.id.action_moticoins); moticoinsItem.setTitle(String.format(getResources().getString(R.string.moticoins_value), appPreferences.getMoticoins())); return true; }
Example 7
Source File: EarthquakeMainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
@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 8
Source File: SearchActivity.java From good-weather with GNU General Public License v3.0 | 6 votes |
private void setupSearchView() { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); SearchView searchView = (SearchView) findViewById(R.id.search_view); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconified(false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mSearchCityAdapter.getFilter().filter(query); return true; } @Override public boolean onQueryTextChange(String newText) { mSearchCityAdapter.getFilter().filter(newText); return true; } }); }
Example 9
Source File: HomeActivity.java From QuranAndroid with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_activity_home, menu); //init search in the toolbar SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); //listener for click in search button searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { startActivity(new Intent(HomeActivity.this, SearchActivity.class) .putExtra(AppConstants.General.SEARCH_TEXT, query)); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); return true; }
Example 10
Source File: MainActivity.java From moviedb-android with Apache License 2.0 | 5 votes |
/** * Initialize the contents of the Activity's standard options menu. * This is only called once, the first time the options menu is displayed. * * @param menu the options menu in which we place our items. * @return You must return true for the menu to be displayed; if you return false it will not be shown. */ @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); searchViewItem = menu.findItem(R.id.search); searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem); searchView.setQueryHint(getResources().getString(R.string.search_hint)); searchView.setOnQueryTextListener(searchViewOnQueryTextListener); searchView.setOnSuggestionListener(searchSuggestionListener); // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchViewItemC = (SearchView) menu.findItem(R.id.search).getActionView(); searchViewItemC.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); String[] from = {SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2}; int[] to = {R.id.posterPath, R.id.title, R.id.info}; searchAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.suggestionrow, null, from, to, 0) { @Override public void changeCursor(Cursor cursor) { super.swapCursor(cursor); } }; searchViewItemC.setSuggestionsAdapter(searchAdapter); MenuItemCompat.setOnActionExpandListener(searchViewItem, onSearchViewItemExpand); return true; }
Example 11
Source File: RecipeItemListActivity.java From android-recipes-app with Apache License 2.0 | 5 votes |
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 12
Source File: CustomersFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.customer_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.customer_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 13
Source File: AlbumSearchActivity.java From android-samples with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_album_search, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(this); return true; }
Example 14
Source File: ProductsFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@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: TransactionActivity.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.transaction_menu, menu); // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { _currentlySearching = false; // Re-populate the transactions onResume(); // false: allow the default cleanup behavior on the search view on closing. return false; } }); searchView.setOnSearchClickListener(new View.OnClickListener() { @Override public void onClick(View v) { _currentlySearching = true; } }); return super.onCreateOptionsMenu(menu); }
Example 16
Source File: AnnounceFragment.java From ForPDA with GNU General Public License v3.0 | 4 votes |
private void addSearchOnPageItem(Menu menu) { toolbar.inflateMenu(R.menu.theme_search_menu); MenuItem searchOnPageMenuItem = menu.findItem(R.id.action_search); searchOnPageMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS); SearchView searchView = (SearchView) searchOnPageMenuItem.getActionView(); searchView.setTag(searchViewTag); searchView.setOnSearchClickListener(v -> { if (searchView.getTag().equals(searchViewTag)) { ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn); if (searchClose != null) ((ViewGroup) searchClose.getParent()).removeView(searchClose); ViewGroup.LayoutParams navButtonsParams = new ViewGroup.LayoutParams(App.px48, App.px48); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.actionBarItemBackground, outValue, true); AppCompatImageButton btnNext = new AppCompatImageButton(searchView.getContext()); btnNext.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_next)); btnNext.setBackgroundResource(outValue.resourceId); AppCompatImageButton btnPrev = new AppCompatImageButton(searchView.getContext()); btnPrev.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_prev)); btnPrev.setBackgroundResource(outValue.resourceId); ((LinearLayout) searchView.getChildAt(0)).addView(btnPrev, navButtonsParams); ((LinearLayout) searchView.getChildAt(0)).addView(btnNext, navButtonsParams); btnNext.setOnClickListener(v1 -> findNext(true)); btnPrev.setOnClickListener(v1 -> findNext(false)); searchViewTag++; } }); SearchManager searchManager = (SearchManager) getMainActivity().getSystemService(Context.SEARCH_SERVICE); if (null != searchManager) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getMainActivity().getComponentName())); } searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { findText(newText); return false; } }); }
Example 17
Source File: WhiteListActivity.java From timecat with Apache License 2.0 | 4 votes |
@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.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: FloatViewWhiteListActivity.java From timecat with Apache License 2.0 | 4 votes |
@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.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; } }); } refreshMenu(false); return true; }
Example 19
Source File: CHMActivity.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_chm, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { webview.clearMatches(); return false; } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { webview.findAllAsync(newText); try { for (Method m : WebView.class.getDeclaredMethods()) { if (m.getName().equals("setFindIsUp")) { m.setAccessible(true); m.invoke((webview), true); break; } } } catch (Exception ignored) { } return false; } }); return true; }
Example 20
Source File: ContactsPickerActivity.java From zom-android-matrix with Apache License 2.0 | 4 votes |
@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; }