[英]android search dialog not working
我已經使用了 androids 指南上的給定教程,並在按下設備或菜單項上的搜索按鈕后完成了所有需要的操作。 它不會打開搜索對話框。 我從這里得到教程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.
}
}
有人可以幫我嗎,為什么我在按下搜索硬件按鈕后看不到搜索對話框。
最后我自己找到了問題的解決方案
<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 中的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.