Android assisted Search: The search button does not invoke the searchable Activity (Other Solutions did not help)

隐身守侯 提交于 2019-11-28 11:24:44

I'm not sure if you've forgotten to add it but your MainActivity misses setting the searchable info on the SearchView:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SearchView searchView = (SearchView) findViewById(R.id.searchActivity_searchView);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}

As a side note:

I've had problems with the default_searchable meta-tag, when using flavors. It seemed to only work when using the full path (skipping the flavor) to the search activity e.g.:

<meta-data 
    android:name="android.app.default_searchable"
    android:value="com.example.SearchActivity"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!