Home » Android » android – How to enable selection markers for EditText in PopupWindow?

android – How to enable selection markers for EditText in PopupWindow?

Posted by: admin May 14, 2020 Leave a comment

Questions:

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);
How to&Answers:

Try this,

   editText.setSelectAllOnFocus(true);