android搜索对话框无效

Uma*_*til 4 search android dialog

我已经在机器人指南上使用了给定的教程,并在按下设备或菜单项上的搜索按钮后仍然完成了所有需要的操作.它不会打开搜索对话框.我从这里获得了教程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>
Run Code Online (Sandbox Code Playgroud)

返回搜索结果的活动

<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>
Run Code Online (Sandbox Code Playgroud)

我在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>
Run Code Online (Sandbox Code Playgroud)

显示结果的活动

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.

    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗,为什么我在按下搜索硬件按钮后看不到搜索对话框.

Uma*_*til 12

最后我自己找到了问题的解决方案

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="XYZ.com"
    android:hint="Search XYZ.com" >
</searchable>
Run Code Online (Sandbox Code Playgroud)

在这里,我使用lablel和提示作为直接字符串.相反,我们需要使用@ string/label我的意思是我们的字符串应该在strings.xml中然后使用它们.这是Android中的错误.