我无法使用SearchView

时间:2017-11-16 10:16:06

标签: java android searchview

image

我在 Android Studio 中尝试使用 SearchView 时遇到问题。当我添加 SearchView 时,它无法正常工作,但当我删除它时,我的应用程序正常运行。当我重建这个项目时。有通知:

"$ adb shell am start -n
"com.example.nguyenkiemhung.myhomework/
com.example.nguyenkiemhung.myhomework.WelcomeActivity" -a
android.intent.action.MAIN -c 
android.intent.category.LAUNCHER
Client not ready yet..Connected to process 4038 
on device samsung-gt_i8552-cab17026"

你能告诉我这里有什么问题吗?谢谢!

1 个答案:

答案 0 :(得分:0)

这可能是因为您尚未在清单中定义搜索视图。您必须声明您的活动是可搜索的;像这样的东西:

<activity android:name=".WelcomeActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
    <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
</activity>

有关详细信息,请查看文档here