我使用了Android指南上提供的教程并按照要求完成,但是在设备或菜单项上点击搜索按钮后,搜索对话框仍未打开。
我从这里获取了教程:http://developer.android.com/guide/topics/search/search-dialog.html
我必须在此发布我的示例代码,以便您可以查看并帮助我纠正错误。需要在其中显示对话框的活动。
<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 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>
显示结果的活动
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.
}
}
请问有人能帮助我吗?为什么我按下搜索硬件按钮后无法看到搜索对话框。
涉及技术方面的问题,请您自行查找相关资料。