本文整理汇总了Java中android.widget.SearchView.setOnQueryTextFocusChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.setOnQueryTextFocusChangeListener方法的具体用法?Java SearchView.setOnQueryTextFocusChangeListener怎么用?Java SearchView.setOnQueryTextFocusChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.SearchView
的用法示例。
在下文中一共展示了SearchView.setOnQueryTextFocusChangeListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureSearchWidget
import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public void configureSearchWidget(
Activity activity, MenuItem menuItem, final TrackController trackController) {
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
searchView.setQueryRefinementEnabled(true);
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// Hide and show trackController when search widget has focus/no focus
if (trackController != null) {
if (hasFocus) {
trackController.hide();
} else {
trackController.show();
}
}
}
});
}
示例2: onCreateOptionsMenu
import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchMenuItem = menu.findItem(R.id.search);
final SearchView searchView =
(SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean queryTextFocused) {
if(!queryTextFocused) {
searchMenuItem.collapseActionView();
searchView.setQuery("", false);
}
}
});
return true;
}
示例3: onCreateOptionsMenu
import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.vk_search_menu, menu);
MenuItem menuItem = menu.findItem(R.id.vk_search);
menuItem.setOnActionExpandListener(this);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
searchView.setOnQueryTextListener(this);
searchView.setOnQueryTextFocusChangeListener(this);
searchView.setQuery(mSearchText, false);
searchView.setIconifiedByDefault(false);
}
示例4: onCreateOptionsMenu
import android.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.menu_homepage, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = (SearchView) (menu.findItem(R.id.search)).getActionView();
// Get diet preference
//final String diet;
if (getIntent().getExtras() != null) {
diet = getIntent().getExtras().getString("DIET");
} else {
diet = "";
}
// Handle query
if (searchView != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
String queryHint = "Search recipes...";
searchView.setQueryHint(queryHint);
searchView.setOnQueryTextFocusChangeListener(new SearchView.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
hideKeyboard(v);
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent loadSearchIntent = new Intent(HomepageActivity.this, LoadResultsActivity.class);
query = searchView.getQuery().toString();
query = encodeQuery(query);
String emptyString = "";
if (diet != null && !diet.equals(emptyString)) {
query = "&q=" + diet + "+" + query;
} else {
query = "&q=" + query;
}
loadSearchIntent.putExtra("DIET", diet);
loadSearchIntent.putExtra("QUERY", query);
loadSearchIntent.putExtra("USERNAME",username);
loadSearchIntent.putExtra("JSON",json);
loadSearchIntent.putExtra("NAME",name);
loadSearchIntent.putExtra("FLAG","user");
startActivity(loadSearchIntent);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
return true;
}
示例5: onCreateOptionsMenu
import android.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.menu_homepage, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = (SearchView) (menu.findItem(R.id.search)).getActionView();
// Get diet preference
//final String diet;
if (getIntent().getExtras() != null) {
diet = getIntent().getExtras().getString("DIET");
} else {
diet = "";
}
// Handle query
if (searchView != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
String queryHint = "Search recipes...";
searchView.setQueryHint(queryHint);
searchView.setOnQueryTextFocusChangeListener(new SearchView.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
hideKeyboard(v);
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent loadSearchIntent = new Intent(HomepageGuestActivity.this, LoadResultsActivity.class);
query = searchView.getQuery().toString();
query = encodeQuery(query);
String emptyString = "";
if (diet != null && !diet.equals(emptyString)) {
query = "&q=" + diet + "+" + query;
} else {
query = "&q=" + query;
}
loadSearchIntent.putExtra("DIET", diet);
loadSearchIntent.putExtra("QUERY", query);
loadSearchIntent.putExtra("USERNAME",username);
loadSearchIntent.putExtra("JSON",json);
loadSearchIntent.putExtra("NAME",name);
loadSearchIntent.putExtra("FLAG","guest");
startActivity(loadSearchIntent);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
return true;
}
示例6: onCreateOptionsMenu
import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
final MenuItem searchMenuItem = menu.findItem(R.id.search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
if(userid.contentEquals("0") || !getString(R.string.subforum_id).contentEquals("0")) {
searchView.setVisibility(View.GONE);
} else {
if(ForegroundColorSetter.getForegroundDark(background)) {
searchMenuItem.setIcon(R.drawable.ic_action_search_dark);
}
}
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View view, boolean queryTextFocused) {
if(!queryTextFocused) {
searchMenuItem.collapseActionView();
searchView.setQuery("", false);
}
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
return false;
}
public boolean onQueryTextSubmit(String query) {
if(getActionBar() != null) {
getActionBar().setSubtitle(baseSubtitle);
}
searchMenuItem.collapseActionView();
searchView.setQuery("", false);
Bundle bundle = new Bundle();
bundle.putString("subforum_name",(String) "Search - " + query);
bundle.putString("subforum_id",(String) "search");
bundle.putString("query",(String) query);
bundle.putString("background",(String) background);
bundle.putString("icon",(String) "n/a");
bundle.putString("inTab",(String) "N");
loadForum(bundle,"SEARCH_QUERY",false);
return false;
}
});
return true;
}