Java Code Examples for androidx.appcompat.widget.SearchView#setOnQueryTextListener()
The following examples show how to use
androidx.appcompat.widget.SearchView#setOnQueryTextListener() .
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: HadithFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MaterialMenuInflater.with(getActivity(), inflater) .setDefaultColorResource(R.color.white) .inflate(R.menu.hadis, menu); mSwitch = menu.findItem(R.id.favswitch); mFav = menu.findItem(R.id.fav); setCurrentPage(mPager.getCurrentItem()); MenuItem item = menu.findItem(R.id.menu_item_share); item.setOnMenuItemClickListener(item1 -> { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share))); return true; }); item = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); }
Example 2
Source File: ContactSelectionActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.group_create_menu, menu); menu.removeItem(R.id.Next); if (disableCheckBox) { menu.removeItem(R.id.Done); } MenuItem searchItem = menu.findItem(R.id.menu_search); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setQueryHint(getResources().getString(R.string.search_hint)); if (Utils.hasICS()) { searchItem.collapseActionView(); } searchView.setOnQueryTextListener(this); searchView.setIconified(true); return super.onCreateOptionsMenu(menu); }
Example 3
Source File: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressLint("NewApi") @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. showActionBar(); //return false; getMenuInflater().inflate(R.menu.mobicom_basic_menu_for_normal_message, menu); MenuItem searchItem = menu.findItem(R.id.menu_search); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setQueryHint(getResources().getString(R.string.search_hint)); if (Utils.hasICS()) { searchItem.collapseActionView(); } searchView.setOnQueryTextListener(this); searchView.setSubmitButtonEnabled(true); searchView.setIconifiedByDefault(true); if (quickConversationFragment != null && !TextUtils.isEmpty(quickConversationFragment.getSearchString())) { searchView.setIconified(false); searchView.setQuery(quickConversationFragment.getSearchString(), false); } return super.onCreateOptionsMenu(menu); }
Example 4
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_menu, menu); MenuItem myActionMenuItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) myActionMenuItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query); if (!searchView.isIconified()) { searchView.setIconified(true); } myActionMenuItem.collapseActionView(); return false; } @Override public boolean onQueryTextChange(String s) { return false; } }); return true; }
Example 5
Source File: SelectFileActivity.java From turbo-editor with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_select_file, menu); mSearchViewMenuItem = menu.findItem(R.id.im_search); mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchViewMenuItem); mSearchView.setIconifiedByDefault(true); mSearchView.setOnQueryTextListener(this); mSearchView.setSubmitButtonEnabled(false); return super.onCreateOptionsMenu(menu); }
Example 6
Source File: NamesFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MaterialMenuInflater.with(getActivity(), inflater) .setDefaultColorResource(R.color.white) .inflate(R.menu.search, menu); MenuItem item = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); }
Example 7
Source File: SmsDragListActivity.java From financisto with GNU General Public License v2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.draglist_menu, menu); final MenuItem searchItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } /** * Not sense doing via android.widget.Filter as adapter and its data is filtered in async mode */ @Override public boolean onQueryTextChange(String newText) { cursorSource.setConstraint(newText); adapter.reloadAsyncSource(); if (!StringUtil.isEmpty(newText)) { Log.i(TAG, "filtered by `" + newText + "`"); // Toast.makeText(SmsDragListActivity.this, "filtered by '" + newText + "'", Toast.LENGTH_SHORT).show(); } return true; } }); final MenuItem newItem = menu.findItem(R.id.new_sms_template); newItem.setOnMenuItemClickListener(this::addItem); return true; }
Example 8
Source File: BottinFragment.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_bottin, menu); // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView = (SearchView) menu.findItem(R.id.menuitem_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(this); super.onCreateOptionsMenu(menu, inflater); }
Example 9
Source File: AddTokensActivity.java From SSForms with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.clear(); getMenuInflater().inflate(R.menu.tokens_picker_menu_main, menu); //super.onCreateOptionsMenu(menu, getMenuInflater()); MenuItem myActionMenuItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); EditText searchEditText = searchView.findViewById(R.id.search_src_text); searchEditText.setTextColor(getResources().getColor(R.color.whiteColor)); searchEditText.setHintTextColor(getResources().getColor(R.color.whiteColor)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { simpleSearchAdapter.filter(""); } else { simpleSearchAdapter.filter(newText); } return true; } }); return true; }
Example 10
Source File: BookShelfSearchView.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void initView(Context context) { LayoutInflater.from(context).inflate(R.layout.view_search_bookshelf, this, true); ButterKnife.bind(this); AppCompat.setToolbarNavIconTint(toolbar, getResources().getColor(R.color.colorBarText)); toolbar.inflateMenu(R.menu.menu_search_view); MenuItem search = toolbar.getMenu().findItem(R.id.action_search); searchView = (SearchView) search.getActionView(); AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.searchShelfBook)); searchAutoComplete = searchView.findViewById(R.id.search_src_text); searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels); searchView.onActionViewExpanded(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { queryBooks(newText); return false; } }); rvList.setLayoutManager(new LinearLayoutManager(context)); adapter = new BookShelfListAdapter(context, -1, 1); rvList.setAdapter(adapter); toolbar.setNavigationOnClickListener(v -> { ViewParent parent = BookShelfSearchView.this.getParent(); if (parent instanceof DrawerLayout) { ((DrawerLayout) parent).closeDrawers(); } }); }
Example 11
Source File: HistoryActivity.java From SimplicityBrowser with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_b_h, menu); searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setIconified(true); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getResources().getString(R.string.search_history)); searchView.setMaxWidth(Integer.MAX_VALUE); return true; }
Example 12
Source File: SearchActivity.java From WanAndroid with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem menuItem = menu.findItem(R.id.item_search); //得到SearchView mSearchView = (SearchView)menuItem.getActionView(); mSearchAutoComplete = mSearchView.findViewById(R.id.search_src_text); mSearchView.setMaxWidth(R.dimen.dp_400);//设置最大宽度 mSearchView.setSubmitButtonEnabled(true);//设置是否显示搜索框展开时的提交按钮 mSearchView.setQueryHint(getResources().getString(R.string.searchActivity_hint));//设置输入框提示语 mSearchView.onActionViewExpanded();//设置搜索框直接展开显示。左侧有放大镜(在搜索框中) 右侧无叉叉 有输入内容后有叉叉 不能关闭搜索框 mSearchAutoComplete.setTextColor(getResources().getColor(R.color.white));//设置内容文字颜色 //搜索框文字变化监听,搜索按钮监听 mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mPresenter.addHistoryRecord(query); mPresenter.loadSearchResquest(query, 0); isLoadMore = false; return false; } @Override public boolean onQueryTextChange(String newText) { mPresenter.clearAllSearchKey(newText); return false; } }); return super.onCreateOptionsMenu(menu); }
Example 13
Source File: ChapterListActivity.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search_view, menu); MenuItem search = menu.findItem(R.id.action_search); searchView = (SearchView) search.getActionView(); ATH.setTint(searchView, MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.primaryColor(this)))); searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels); searchView.onActionViewCollapsed(); searchView.setOnCloseListener(() -> { mTlIndicator.setVisibility(VISIBLE); return false; }); searchView.setOnSearchClickListener(view -> mTlIndicator.setVisibility(GONE)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (mTlIndicator.getSelectedTabPosition() == 1) { ((BookmarkFragment) mFragmentList.get(1)).startSearch(newText); } else { ((ChapterListFragment) mFragmentList.get(0)).startSearch(newText); } return false; } }); return super.onCreateOptionsMenu(menu); }
Example 14
Source File: NetFragment.java From pandora with Apache License 2.0 | 5 votes |
private void setSearchView() { MenuItem menuItem = getToolbar().getMenu().findItem(R.id.pd_menu_id_2); SearchView searchView = (SearchView) menuItem.getActionView(); searchView.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); searchView.setQueryHint(ViewKnife.getString(R.string.pd_net_search_hint)); searchView.setOnQueryTextListener(new SimpleOnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { filter(newText); return true; } @Override public boolean onQueryTextSubmit(String query) { closeSoftInput(); filter(query); return true; } }); SimpleOnActionExpandListener.bind(menuItem, new SimpleOnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem item) { loadData(); return true; } }); }
Example 15
Source File: SearchCityFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MaterialMenuInflater.with(getActivity(), inflater) .setDefaultColorResource(R.color.white) .inflate(R.menu.search, menu); mSearchItem = menu.findItem(R.id.menu_search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.performClick(); mSearchView.setOnQueryTextListener(this); }
Example 16
Source File: RadioFragment.java From TDTChannels-APP with MIT License | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.fragment_radio, menu); MenuItem searchItem = menu.findItem(R.id.action_search); isShowingFavorites = false; // Change color of the search button if (getContext() != null) { Drawable drawable = DrawableCompat.wrap(searchItem.getIcon()); DrawableCompat.setTint(drawable, ContextCompat.getColor(getContext(), R.color.white)); menu.findItem(R.id.action_search).setIcon(drawable); } SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { // This will be fired every time you input any character. if (mFilter != null) { mFilter.filter(newText); } return false; } }); }
Example 17
Source File: TVFragment.java From TDTChannels-APP with MIT License | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.fragment_tv, menu); MenuItem searchItem = menu.findItem(R.id.action_search); isShowingFavorites = false; // Change color of the search button if (getContext() != null) { Drawable drawable = DrawableCompat.wrap(searchItem.getIcon()); DrawableCompat.setTint(drawable, ContextCompat.getColor(getContext(), R.color.white)); menu.findItem(R.id.action_search).setIcon(drawable); } SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { // This will be fired every time you input any character. if (mFilter != null) { mFilter.filter(newText); } return false; } }); }
Example 18
Source File: NamesFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MaterialMenuInflater.with(getActivity(), inflater) .setDefaultColorResource(R.color.white) .inflate(R.menu.search, menu); MenuItem item = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); }
Example 19
Source File: ModulesFragment.java From EdXposedManager with GNU General Public License v3.0 | 4 votes |
@Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.menu_modules, menu); mSearchView = (SearchView) menu.findItem(R.id.app_search).getActionView(); mSearchView.setOnQueryTextListener(mSearchListener); }
Example 20
Source File: ApplicationFragment.java From EdXposedManager with GNU General Public License v3.0 | 4 votes |
@Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.menu_app_list, menu); mSearchView = (SearchView) menu.findItem(R.id.app_search).getActionView(); mSearchView.setOnQueryTextListener(mSearchListener); }