在 SearchView 打开的情况下开始活动 [英] Start Activity with SearchView open
本文介绍了在 SearchView 打开的情况下开始活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在文本字段打开的情况下使用 SearchView 开始活动.通过这种方式,我无需点击望远镜即可进行搜索.我正在使用 Sherlock 操作栏.
how can I start an activity with a SearchView with the text field open. In this way I could search without having to click on the spyglass. I am using Sherlock Action Bar.
这是我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Cerca domande");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (query.length() != 0) {
// handle search here
return true;
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.length()>=3) {
new PostTask().execute(newText);
Util.setSharedPreferences(SearchActivity.this, "lastsearch", newText);
}
return false;
}
});
menu.add("Search")
.setIcon(ic_search_inverse)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
listsearch.setOnItemClickListener(this);
return true;
}
谢谢.
推荐答案
试过这个了吗?
searchMenu.expandActionView();
在OnCreateOptionsMenu()
menu.add("Search")
.setIcon(ic_search_inverse)
.setActionView(searchView)
.expandActionView();
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
您可以添加焦点,打开软键盘.因此,一切都已准备好供用户输入和搜索.
you can add focus, open soft-keyboard. So, that everything is ready for user to type in and search.
但这不是标准行为.
这篇关于在 SearchView 打开的情况下开始活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文