Java Code Examples for android.support.v4.view.MenuItemCompat#setOnActionExpandListener()
The following examples show how to use
android.support.v4.view.MenuItemCompat#setOnActionExpandListener() .
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 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 2
Source File: SearchActivity.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false); if (isInputMode) { MenuItemCompat.expandActionView(searchItem); } else { MenuItemCompat.collapseActionView(searchItem); } MenuItemCompat.setOnActionExpandListener(searchItem, this); AutoCompleteTextView autoCompleteTextView = searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); autoCompleteTextView.setThreshold(0); autoCompleteTextView.setAdapter(new ArrayAdapter<>(this, R.layout.layout_item_simple_list, mPresenter.getSearchRecordList())); autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity()))); autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> { onQueryTextSubmit(parent.getAdapter().getItem(position).toString()); }); return super.onCreateOptionsMenu(menu); }
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: MainActivity.java From ruby-china-android with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); MenuItemCompat.setOnActionExpandListener(searchItem, new SearchExpandListener(this)); return true; }
Example 5
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 6
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 7
Source File: ForumActivity.java From uservoice-android-sdk with MIT License | 5 votes |
@SuppressLint("NewApi") @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.uv_forum, menu); MenuItem searchItem = menu.findItem(R.id.uv_menu_search); if (hasActionBar()) { MenuItemCompat.setOnActionExpandListener(searchItem, new SearchExpandListener(this)); SearchView search = (SearchView) MenuItemCompat.getActionView(searchItem); search.setOnQueryTextListener(new SearchQueryListener(this)); } else { searchItem.setVisible(false); } menu.findItem(R.id.uv_new_idea).setVisible(Session.getInstance().getConfig(this).shouldShowPostIdea()); return true; }
Example 8
Source File: ThreadFragment.java From Ouroboros with GNU General Public License v3.0 | 4 votes |
@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); }