现在我在搜索栏中显示以下代码。
链接:http://pastebin.com/6vSBR8iX
如何让它成为像市场一样的搜索窗口类型?
这是我的Android清单。
链接:http://pastebin.com/ue6NSTCr
有人请帮我解决这个问题。我试过了
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
但无法进行搜索。
答案 0 :(得分:0)
您是否按照指南进行操作:http://developer.android.com/guide/topics/search/search-dialog.html#PerformingSearch
如果你已经创建了Activity和Action Bar Widget,我希望你不要忘记添加:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the options menu from XML
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_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).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search:
onSearchRequested();
return true;
default:
return false;
}
}
为了澄清您的问题,请您发布更多信息吗?
干杯!