public boolean onOptionsItemSelected(MenuItem item) {
int itemThatWasClickedId = item.getItemId();
if (itemThatWasClickedId == R.id.action_search) {
Context context = MainActivity.this;
String textToShow = "Search clicked";
Toast.makeText(context, textToShow, Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item); //这样的返回有什么意思呢
}
}
onOptionsItemSelected返回值作用
根据API说明可以知道:
boolean Return false to allow normal menu processing to proceed, true to consume it here.
onOptionsItemSelected的返回值意思:
true表示该方法执行完毕后,点击事件不会再向下一个事件处理方法传递了。
false表示执行完该方法后,点击事件继续向下传递。