searchManager.getSearchableInfo(getComponentName()) returns null

后端 未结 3 892
有刺的猬
有刺的猬 2021-01-11 13:03

I\'ve followed this Android guide in order to add a search bar to an activity. The setup looks like this:

res/menu/activity_main.xml:



        
相关标签:
3条回答
  • 2021-01-11 13:25

    Add it to the activity where you've put your SearchView

    <meta-data
        android:name="android.app.default_searchable"
        android:value=".activity_that_handles_the_search" />
    
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
    
    0 讨论(0)
  • 2021-01-11 13:35

    Replace:

    android:actionViewClass="android.widget.SearchView"
    

    With:

    app:actionViewClass="android.widget.SearchView"
    

    Because app is often used if you are using support library.

    0 讨论(0)
  • 2021-01-11 13:37

    In my case the problem was my mistake during integration with ActionBarSherlock. In this case android:actionViewClass should be com.actionbarsherlock.widget.SearchView instead of android.widget.SearchView. I know this sounds dumb, but I spent 20 minutes trying to figure out why searchView is null in my code that is similar to yours.

    0 讨论(0)
提交回复
热议问题