我在 androids 指南中使用了给定的教程,并在按下设备或菜单项上的搜索按钮后完成了所有需要的操作。它不会打开搜索对话框。
我从这里得到了教程 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>
在这里,我使用了 labell 和 hint 作为直接字符串。相反,我们需要使用@string/label
我的意思是我们的字符串应该在strings.xml 中然后使用它们。
这是Android中的错误。