1
我在考慮將我的搜索活動從主要活動中解耦出來,但是停滯不前。下面的例子「假設當前活動是可搜索的活動」。配置Android搜索小部件時,如果當前活動不是可搜索活動,您會怎麼做?
如果當前活動是而不是可搜索活動,您將如何繼續?我應該用什麼替換getComponentName()
?
從http://developer.android.com/guide/topics/search/search-dialog.html
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the options menu from XML
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
return true;
}
See Sloy's ans更多這裏 http://stackoverflow.com/questions/11699206/cannot-get-searchview-in-actionbar-to-work 希望它有幫助。 – SuShiS