上下文操作菜单无法直观地超过片段中的操作栏位置

Mar*_*cus 4 android android-fragments

我有Activity一个Fragment包含ListView项目的项目,用户可以在其上单击并调用上下文操作模式.

我喜欢发生的是文档说明:

上下文操作栏不一定与操作栏相关联.它们独立运行,即使上下文操作栏在视觉上超过了操作栏位置.

但是,这是我目前正在经历的行为.截至目前,所述上下文动作模式出现以上ActionBar,如下面所示的附图.

当前

到目前为止我没有成功的尝试:

  • ActionMode逻辑从Fragment主机移动到主机Activity.
  • <item name="windowActionModeOverlay">true</item>在我的主题中设置.
  • 打电话getActivity().getMenuInflater()而不是mode.getMenuInflater().

这是我调用Contextual Action Menu的代码

public class NotesFragment extends Fragment implements View.OnClickListener{

    private ActionMode mActionMode;

    @Override
    public void checkBoxChecked(Note which) {
        if (mActionMode == null)
            mActionMode = getActivity().startActionMode(mActionModeCallback);
    }

    private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.context, menu);
            return true;
        }

        // Called each time the action mode is shown. 
        // Always called after onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            return false; // Return false if nothing is done
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
                case R.id.context_delete:
                    //Do work unrelated to topic
                    mode.finish(); // Action picked, so close the CAB
                    return true;
                case R.id.context_move:
                    //Do work unrelated to topic
                    mode.finish(); // Action picked, so close the CAB
                    return true;
                default:
                    return false;
            }
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mActionMode = null;
        }
    };

}
Run Code Online (Sandbox Code Playgroud)

编辑:这是Activity,其中Fragment居住地:

public class MainActivity extends ActionBarActivity implements DialogFragmentMoveNote.DialogFragmentMoveNoteListener,
        DialogFragmentRemoveNote.DialogFragmentRemoveNoteListener, DialogFragmentAddNewFolder.DialogFragmentAddNewFolderListener,
        DialogFragmentDeleteFolder.DialogFragmentDeleteFolderListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public void onAddNewFolderPositiveClick(Folder folder) {
        //Tell the fragment to do work
    }

    @Override
    public void onRemoveNotesPositiveClick() {
        //Tell the fragment to do work
    }

    @Override
    public void onMoveNotePositiveClick(String chosenFolder) {
        //Tell the fragment to do work
    }

    @Override
    public void onDeleteFolderPositiveClick() {
        //Tell the fragment to do work
    }

    private void displayNoteDetailsFromWidget(String noteId){
        //Tell the fragment to do work
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么上下文操作菜单在视觉上不会超过ActionBar,因为文档状态应该如此?

Mar*_*cus 5

对此的解决方案是添加

<item name="android:windowActionModeOverlay">true</item>
Run Code Online (Sandbox Code Playgroud)

对我Theme来说,现在看起来像

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowActionModeOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

看完这个答案后我找到了解决方案