How to enable selection markers for EditText in Po

2019-03-18 13:33发布

问题:

I'm using a EditText in a PopupWindow. It shows OK, but the selection markers do not show up in the EditText. Neither does the Options menu change when I long press in the EditText. In LogCat I see a warning

TextView does not support text selection. Action mode cancelled.

As a result, the EditText cannot copy/paste text from the clipboard. Is there any way to get the "normal" EditText behaviour in a PopupWindow?

This code shows the problem, but I have also tried lots of variations:

EditText edit = new EditText(getContext());
edit.setBackgroundColor(Color.BLUE);
PopupWindow popup = new PopupWindow(edit, 100, 100, true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(this, Gravity.NO_GRAVITY, 100, 200);

回答1:

Try this,

   editText.setSelectAllOnFocus(true);