本文整理汇总了Java中android.support.v7.widget.SearchView.setOnQueryTextFocusChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.setOnQueryTextFocusChangeListener方法的具体用法?Java SearchView.setOnQueryTextFocusChangeListener怎么用?Java SearchView.setOnQueryTextFocusChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SearchView
的用法示例。
在下文中一共展示了SearchView.setOnQueryTextFocusChangeListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.filesystem__menu, menu);
_searchItem = menu.findItem(R.id.action_search);
_searchView = (SearchView) _searchItem.getActionView();
SearchManager searchManager = (SearchManager) _context.getSystemService(SEARCH_SERVICE);
_searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
_searchView.setQueryHint(getString(R.string.search_documents));
if (_searchView != null) {
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (query != null) {
if (isVisible())
search(query);
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText != null) {
if (isVisible()) {
if (newText.equalsIgnoreCase("")) {
clearSearchFilter();
} else {
search(newText);
}
}
}
return false;
}
});
_searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
MenuItem item = menu.findItem(R.id.action_import);
if (item != null) {
item.setVisible(hasFocus);
}
if (!hasFocus) {
_searchItem.collapseActionView();
}
});
}
ContextUtils cu = ContextUtils.get();
cu.tintMenuItems(menu, true, Color.WHITE);
cu.setSubMenuIconsVisiblity(menu, true);
}
示例2: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main__menu, menu);
_searchItem = menu.findItem(R.id.action_search_meme);
_searchView = (SearchView) _searchItem.getActionView();
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
_searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
_searchView.setQueryHint(getString(R.string.main__search_meme));
if (_searchView != null) {
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (query != null) {
updateSearchFilter(query);
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText != null) {
updateSearchFilter(newText);
}
return false;
}
});
_searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
_searchItem.collapseActionView();
updateSearchFilter("");
}
}
});
}
return true;
}