【问题标题】:android search dialog not workingandroid搜索对话框不起作用
【发布时间】:2011-08-16 11:09:39
【问题描述】:

我已经使用了 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.

    }
}

谁能帮帮我,为什么我在按下搜索硬件按钮后看不到搜索对话框。

【问题讨论】:

标签: android search dialog


【解决方案1】:

我自己终于找到了解决问题的办法

<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 中的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多