Question

I wrote a custom menu for an ActionMode and passed it to the TextView.setCustomSelectionActionModeCallback(ActionMode) as a custom ActionMode in text selecting process. It works but when I'm clicking on the Items with SubMenu , it shows them just for a second and then ActionMode close and do not let me to select a submenu item. It also happens when I'm using Overflow item when I'm using MenuItem.SHOW_AS_ACTION_IF_ROOM for my itmes. any Idea? I'm using Android ICS

Was it helpful?

Solution

I found that Action Mode is closed/finished when the EditText lost its focus:

TextView.java

@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
    super.onWindowFocusChanged(hasWindowFocus);

    if (mEditor != null) mEditor.onWindowFocusChanged(hasWindowFocus);

    startStopMarquee(hasWindowFocus);
}

Note: EditText is subclass of TextView.

Editor.java

void onWindowFocusChanged(boolean hasWindowFocus) {
    if (hasWindowFocus) {
        ...
    } else {
        ...
        hideControllers();
        ...
    }
}

Solution

I tried to create this:

package com.edwardsp.sample.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

public class CustomEditText extends EditText {

    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        if (hasWindowFocus) {
            super.onWindowFocusChanged(hasWindowFocus);
        }
    }
}

and use the CustomEditText as normal EditText. The action mode submenu can be shown. I didn't find strange behavior in CustomEditText. If someone finds strange behavior from this implementation, please let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top