How to enable selection markers for EditText in PopupWindow?

走远了吗. 提交于 2019-12-09 05:38:04

问题


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);


来源:https://stackoverflow.com/questions/8035159/how-to-enable-selection-markers-for-edittext-in-popupwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!