我正在使用带有 ActionMode 的 Appcompat 的工具栏。ActionMode 覆盖在工具栏上。现在,如果我单击 ActionMode 中的空白空间,工具栏中的底层 ActionButton 将处理 ClickEvent。
这是正常行为吗?我怎样才能防止这种行为?
((ActionBarActivity) getActivity()).getSupportActionBar().startActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
actionMode.getMenuInflater().inflate(R.menu.actionmode, menu);
MenuItem menuItem = menu.findItem(R.id.number);
MenuItem menuItem1 = menu.findItem(R.id.action_edit);
TextView textView = (TextView) menuItem.getActionView();
ImageButton imageButton = (ImageButton) menuItem1.getActionView();
imageButton.setBackgroundResource(R.drawable.ic_action_edit);
textView.setText("0 selected");
// Return true so that the action mode is shown
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
// As we do not need to modify the menu before displayed, we return false.
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
// Similar to menu handling in Activity.onOptionsItemSelected()
switch (menuItem.getItemId()) {
case R.id.action_delete:
// Some remove functionality
return true;
}
return true;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
// Allows you to be notified when the action mode is dismissed
}
});
/res/values/menu 中我的 ActionMode 的 XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/number"
android:title="number"
android:actionViewClass="android.widget.TextView"/>
<item android:id="@+id/action_edit"
android:title="edit"
android:actionViewClass="android.widget.ImageButton"/>
<item android:id="@+id/action_delete"
android:title="delete"
android:icon="@drawable/ic_action_delete"/>
</menu>