本文整理汇总了Java中android.support.v7.widget.SearchView类的典型用法代码示例。如果您正苦于以下问题:Java SearchView类的具体用法?Java SearchView怎么用?Java SearchView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchView类属于android.support.v7.widget包,在下文中一共展示了SearchView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
/*简单查询*/
final MenuItem item = menu.findItem(R.id.action_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(item);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
paraMap.put("keyWord", query);
showLoading();
refresh = true;
presenter.getData(1, SIZE, paraMap);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return true;
}
示例2: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@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);
SearchView searchView = (SearchView) menu.findItem(R.id.search_btn).getActionView();
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.requestFocus(1);
//searchView.setSubmitButtonEnabled(true);
return true;
}
示例3: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if(loaderId == DELETED_LOADER_ID){
inflater.inflate(R.menu.menu_fragment_bin, menu);
}
// Place an action bar item for searching.
MenuItem item = menu.add("Search");
item.setIcon(R.drawable.ic_search_white_24dp);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
searchView = new SearchView(myActivity);
searchView.setMaxWidth(Integer.MAX_VALUE);
// Set searchbox text to white
EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
searchEditText.setHintTextColor(ContextCompat.getColor(getContext(), R.color.white));
searchView.setOnQueryTextListener(this);
item.setActionView(searchView);
super.onCreateOptionsMenu(menu, inflater);
}
示例4: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
final MenuItem item = menu.findItem(R.id.action_search);
SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(item);
mSearchView.setIconifiedByDefault(true);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (shouldShowFAQ)
((Searchable) currentFragment).setSearchText(newText);
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
示例5: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.questions, menu);
// Setup search widget in action bar
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setQueryHint(getString(R.string.search_hint));
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override public boolean onQueryTextSubmit(String query) {
return false;
}
@Override public boolean onQueryTextChange(String newText) {
presenter.search(newText);
return true;
}
});
return true;
}
示例6: buildMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_next_search, menu);
MenuItem nextMenuItem = menu.findItem(R.id.action_next);
int flags = MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
MenuItemCompat.setShowAsAction(nextMenuItem, flags);
nextMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().onAppsSelected();
return true;
}
});
SearchView searchView = new SearchView(getActivity());
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
MenuItemCompat.setActionView(searchMenuItem, searchView);
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
searchView.setOnQueryTextListener(this);
return true;
}
示例7: setupSearchView
import android.support.v7.widget.SearchView; //导入依赖的package包/类
private void setupSearchView(Menu menu) {
ActionBar actionBar = getSupportActionBar();
Context context = actionBar != null ? actionBar.getThemedContext() : this;
SearchView searchView = new SearchView(context);
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String queryText) {
mEasyRecycleAdapter.setItems(new ArrayList<PointOfInterest>());
if (queryText.length() > 0) {
getAutocompleteResults(queryText);
} else {
mSubscriptions.unsubscribe();
mProgressBar.setVisibility(View.GONE);
}
return false;
}
});
searchView.requestFocus();
menu.findItem(R.id.action_search).setActionView(searchView);
}
示例8: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.project_menu, menu);
sortByName = menu.findItem(R.id.menu_sort_by_name);
sortByTimeSpent = menu.findItem(R.id.menu_sort_by_time);
sortByName.setChecked(isSortedByName);
sortByTimeSpent.setChecked(isSortedByName);
sortData();
final MenuItem searchItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setQueryHint(context.getString(R.string.search_hint));
searchView.setOnQueryTextListener(this);
}
示例9: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
try {
// inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main_actionbar, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView =
(SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
}catch(Exception ex){
LogHelper.e(LOG_TAG, ex.getMessage());
}finally {
return super.onCreateOptionsMenu(menu);
}
}
示例10: onCreateView
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search_bookmarks, container, false);
initViews(view);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
presenter.loadResults(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
presenter.loadResults(newText);
return true;
}
});
return view;
}
示例11: setupSearchView
import android.support.v7.widget.SearchView; //导入依赖的package包/类
private void setupSearchView() {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
adapter.getFilter().filter(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
if(searchView.getQuery().length() == 0) {
adapter.getFilter().filter("");
}
return true;
}
});
}
示例12: onPrepareOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean res = super.onPrepareOptionsMenu(menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
getWebViewCoordinator().onQueryByText(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return res;
}
示例13: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.filter_menu, menu); // inflate the filter
MenuItem searchViewItem = menu.findItem(R.id.filter_keyword);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
filter.filter("K:" + searchView.getQuery());
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
filter.filter("K:" + searchView.getQuery());
return false;
}
});
return true;
}
示例14: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.latest_menu, menu);
getMenuInflater().inflate(R.menu.filter_menu, menu);
MenuItem searchViewItem = menu.findItem(R.id.filter_keyword);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
filter.filter("K:" + searchView.getQuery());
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
filter.filter("K:" + searchView.getQuery());
return false;
}
});
return true;
}
示例15: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nav, menu);
SearchManager searchManager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
searchMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.
getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
return true;
}