我已经使用了机器人指南上的给定教程,并在按下设备或菜单项上的搜索按钮后完成了所有需要做的事情。它不会打开搜索对话框。 我从这里得到教程http://developer.android.com/guide/topics/search/search-dialog.html
我必须在这里发布我的示例代码,这样你们就可以查看它并在可能的情况下提供帮助,这样我就可以知道我哪里出错了。 应该出现对话框的 Activity
<activity android:name=".testAndroid"
android:theme="@android:style/Theme.NoTitleBar">
<meta-data android:name="android.app.default_searchable"
android:value="com.tester.android.Search" />
</activity>
返回搜索结果的 Activity
<activity android:name=".Search" android:label="Search">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
</activity>
我在 res/xml 文件夹中的可搜索文件
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="XYZ.com"
android:hint="Search XYZ.com" >
</searchable>
显示结果的 Activity
public class Search extends ListActivity {
private Vector<?> loadedArticles;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.articles);
Intent intent = getIntent();
String query="";
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
query = intent.getStringExtra(SearchManager.QUERY);
}
boolean articlesLoaded = findArticles(query); // it shows results and renders it.
}
}
谁能帮帮我,为什么我在按下搜索硬件按钮后看不到搜索对话框。
最佳答案
最后我自己找到了解决问题的方法
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="XYZ.com"
android:hint="Search XYZ.com" >
</searchable>
这里我使用了 label 和 hint 作为直接字符串。相反,我们需要使用 @string/label 我的意思是我们的字符串应该在 strings.xml 中然后使用它们。 这是 Android 中的错误。
关于android 搜索对话框不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077249/