嘿伙计们,我正在尝试在我的应用程序中实现Seach,其中我在ToolBar中添加了一个搜索菜单项。当我点击搜索图标时,它给了我:
如何让它进入工具栏(后面的黄色栏?
我可搜索的xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:voiceSearchMode="showVoiceSearchButton"
android:hint="@string/search_hint" />
我的宣言:
<activity
android:name=".ListLoaderActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/search" />
</activity>
我的活动:
@Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
//Toast.makeText(SearchActivity.this, "Nothing to search for", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.about: {
MyMessageDialog.displayMessage(ListLoaderActivity.this, "Stock Predictions");
return true;
}case R.id.search:{
onSearchRequested();
return true;
}
default: {
return false;
}
}
}