1

I'm working on an ICS (4.0.3) tablet app where we're using DialogFrament extensively. When the user does a long press inside a text editor in a dialog fragment I need to prevent the copy/paste action bar from appearing at the top of the screen. Fortunately we have our own base class extending DialogFragment (call it MyOrgDialogFragment) that all our dialog fragments are based on, so I can modify that if required.

My first attempt has involved overriding OnCreateDialog() in MyOrgDialogFragment, then overriding onWindowStartingActionMode() inside that, i.e.:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    return new Dialog(getActivity()) {
        @Override
        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback)
        {
            return new ActionMode()
            {
                // [ All overrides empty ]
            }
        }
    };
}

This nearly works: it prevents the action bar from appearing, and the selection handles still appear when I long-press in an edit field (which is fine), but the selection handles aren't dismissed correctly when I move focus onto another edit field. I end up with "zombie" selection handles hovering over each edit field I've made a selection in.

Can anyone point me towards a better solution?

4

1 回答 1

4

查看可用于/的setCustomSelectionActionModeCallback方法。如果你使用这样的空:TextViewEditTextActionMode.Callback

private ActionMode.Callback mModeCallback = new Callback() {

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            // TODO Auto-generated method stub

        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // TODO Auto-generated method stub
            return false;
        }
    };

选择ActionMode将被阻止(切换字段时没有选择处理程序,实际上它们根本不会出现)。

于 2013-02-01T10:42:26.470 回答