Java Code Examples for android.support.v7.widget.SearchView#setOnCloseListener()
The following examples show how to use
android.support.v7.widget.SearchView#setOnCloseListener() .
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: 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 2
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 3
Source File: TaskListFragment.java From mvp-helpers with MIT License | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.task_list_menu, menu); final MenuItem item = menu.findItem(R.id.action_search); final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (null != actionBar) { final SearchView searchView = new SearchView(actionBar.getThemedContext()); MenuItemCompat.setActionView(item, searchView); searchView.setOnQueryTextListener(this); searchView.setIconifiedByDefault(false); searchView.setOnSearchClickListener(v -> newTaskButton.hide()); searchView.setOnCloseListener(this::onClose); MenuItemCompat.setOnActionExpandListener(item, this); } if (isPresenterAvailable()) { Long count = getPresenter().getTasksCount(); menu.findItem(R.id.action_delete_all).setEnabled(count != 0); menu.findItem(R.id.action_delete_all).setVisible(count != 0); } super.onCreateOptionsMenu(menu, inflater); }
Example 4
Source File: BaseFragment.java From framework with GNU Affero General Public License v3.0 | 5 votes |
public void setHasSearchView(IOnSearchViewChangeListener listener, Menu menu, int menu_id) { mOnSearchViewChangeListener = listener; mSearchView = (SearchView) MenuItemCompat.getActionView(menu .findItem(menu_id)); if (mSearchView != null) { mSearchView.setOnCloseListener(closeListener); mSearchView.setOnQueryTextListener(searchViewQueryListener); mSearchView.setIconifiedByDefault(true); } }
Example 5
Source File: BaseFragment.java From hr with GNU Affero General Public License v3.0 | 5 votes |
public void setHasSearchView(IOnSearchViewChangeListener listener, Menu menu, int menu_id) { mOnSearchViewChangeListener = listener; mSearchView = (SearchView) MenuItemCompat.getActionView(menu .findItem(menu_id)); if (mSearchView != null) { mSearchView.setOnCloseListener(closeListener); mSearchView.setOnQueryTextListener(searchViewQueryListener); mSearchView.setIconifiedByDefault(true); } }
Example 6
Source File: HomeActivity.java From Pasta-for-Spotify with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query, false); return true; } @Override public boolean onQueryTextChange(String newText) { if (preload) search(newText, true); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { if (f instanceof SearchFragment) onBackPressed(); return false; } }); return super.onCreateOptionsMenu(menu); }
Example 7
Source File: ReadCHMActivity.java From BookReader with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_chm_reader, menu); MenuItem searchMenuItem = menu.findItem(R.id.menu_search);//在菜单中找到对应控件的item SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { mWebView.clearMatches(); return false; } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { mWebView.findAllAsync(newText); try { for (Method m : WebView.class.getDeclaredMethods()) { if (m.getName().equals("setFindIsUp")) { m.setAccessible(true); m.invoke(mWebView, true); break; } } } catch (Exception ignored) { } return false; } }); return true; }
Example 8
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 9
Source File: SearchActivity.java From Theogony with MIT License | 5 votes |
private void setupSearchView(final SearchView searchView) { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconified(false); // xml中设置不起作用 searchView.setOnQueryTextListener(this); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { return true; } }); }
Example 10
Source File: HomeActivity.java From Pasta-Music with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query, false); return true; } @Override public boolean onQueryTextChange(String newText) { if (preload) search(newText, true); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { if (f instanceof SearchFragment) onBackPressed(); return false; } }); return super.onCreateOptionsMenu(menu); }
Example 11
Source File: MusicFragment.java From TouchNews with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_music, menu); super.onCreateOptionsMenu(menu, inflater); mMenuItemSearch = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search)); mMenuItemSearch.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { mListView.setVisibility(View.GONE); //刷新待选List 为默认值 updateSearchList(mSearchChooseDef); return false; } }); //文本输入框可见、显示ListView mMenuItemSearch.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mListView.setVisibility(View.VISIBLE); } } }); mMenuItemSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { //文本输入改变实时搜索关键字 mMusicsPresenter.searchMusic(newText); //文本输入改变 List 滑动到顶部 mListView.setSelection(0); return true; } }); }
Example 12
Source File: AllCurrencyListFragment.java From CryptoBuddy with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) { getActivity().getMenuInflater().inflate(R.menu.all_currency_list_tab_menu, menu); searchItem = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); // Detect SearchView icon clicks searchView.setOnSearchClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchViewFocused = true; setItemsVisibility(menu, searchItem, false); drawerController.hideHamburger(); } }); // Detect SearchView close searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { searchViewFocused = false; setItemsVisibility(menu, searchItem, true); drawerController.showHamburger(); return false; } }); if (searchViewFocused) ((AppCompatActivity)mContext).getSupportActionBar().setTitle(""); super.onCreateOptionsMenu(menu, inflater); }
Example 13
Source File: ActivityMain.java From Android-Firewall with GNU General Public License v3.0 | 5 votes |
@Override+ public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); // Search searchItem = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (adapter != null) adapter.getFilter().filter(query); return true; } @Override public boolean onQueryTextChange(String newText) { if (adapter != null) adapter.getFilter().filter(newText); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { if (adapter != null) adapter.getFilter().filter(null); return true; } }); return true; }
Example 14
Source File: ReadCHMActivity.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_chm_reader, menu); MenuItem searchMenuItem = menu.findItem(R.id.menu_search);//在菜单中找到对应控件的item SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { mWebView.clearMatches(); return false; } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { mWebView.findAllAsync(newText); try { for (Method m : WebView.class.getDeclaredMethods()) { if (m.getName().equals("setFindIsUp")) { m.setAccessible(true); m.invoke(mWebView, true); break; } } } catch (Exception ignored) { } return false; } }); return true; }
Example 15
Source File: MainActivity.java From NintendoSwitchEShopHelper with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_view, menu); MenuItem searchItem = menu.findItem(R.id.menu_item_search); final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { QueryPreferences.setStoredQuery(mContext, query); updateItems(); searchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { QueryPreferences.setStoredQuery(mContext, newText.equals("") ? null : newText); updateItems(); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { QueryPreferences.setStoredQuery(mContext, null); updateItems(); searchView.onActionViewCollapsed(); return true; } }); return super.onCreateOptionsMenu(menu); }
Example 16
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 17
Source File: XposedAppManagerActivity.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.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: 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 19
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; }