我无法在任何地方找到如何使用searchManager.getSearchableInfo()支持v7 appcompat库.
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main,menu); MenuItem menuItem = (MenuItem) menu.findItem(R.id.search_widget); SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem); searchView.setSubmitButtonEnabled(true); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); return true; }
这是我得到的:
Call requires API level 8 (current min is 7): android.app.SearchManager#getSearchableInfo MainActivity.java /MyApp/src/com/aat line 113 Android Lint Problem
如果我用@TargetApi忽略错误,我得到这个:
11-21 22:14:48.108: E/AndroidRuntime(2387): java.lang.NoSuchMethodError: android.app.SearchManager.getSearchableInfo
有帮助吗?
解决方法
您是否尝试过使用SearchViewCompat for API 7的actionBarShelock?
Best alternative for SearchView for Android api level 7 and up?