我正在使用ActionBarActivity,如何在API级别8+中支持searchItem.setOnActionExpandListener?它表示最低API级别14是必需的.
下面是我的代码,目前我正在抑制错误并仅在API> = 14时允许代码执行.
@SuppressLint("NewApi") public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.action_bar_home_screen, menu); searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat .getActionView(searchItem); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { searchItem.setOnActionExpandListener(new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { hideProgressBar(); return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { showProgressBar(); selectItem(lastSelectedItemPosition); return true; } }); } }
ianhanniball.. 11
使用MenuItemCompat.setOnActionExpandListener,它是的后端口OnActionExpandedListener
.
使用MenuItemCompat.setOnActionExpandListener,它是的后端口OnActionExpandedListener
.