【发布时间】:2014-12-27 07:28:32
【问题描述】:
长按后,我的 EditText 不显示默认的 ContextMenu(复制、粘贴、选择、全选)。我必须创建自己的 ContextMenu 吗?
下面是来自一个函数的 sn-ps,该函数被调用以创建此 EditText 所在的弹出菜单。
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
popupView = layoutInflater.inflate(R.layout.add_recipe_pop,null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
EditText recipe_url = (EditText)popupView.findViewById(R.id.recipe_url_text);
recipe_url.setLongClickable(true);
registerForContextMenu(recipe_url);
popupWindow.setFocusable(true);
popupWindow.update();
popupWindow.showAtLocation(v,Gravity.CENTER,0,0);
这是 add_recipe_pop XML 的一部分,而 EditText 只是在一个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#E6E6E6"
android:orientation="vertical" >
<EditText
android:id="@+id/recipe_url_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/add_recipe_hint"
android:inputType="textUri"
/>
我尝试过使用 EditText 可聚焦和 setTextSelectable 属性,但如果我这样做,键盘不会出现。感谢您的帮助! :)
【问题讨论】:
-
该功能称为剪贴板,请查看此链接。 stackoverflow.com/questions/25580288/…
-
使用 setfocusableintouchmode.. 不,您不必创建自己的上下文菜单,是设备默认设置.. 并删除
recipe_url.setLongClickable(true); registerForContextMenu(recipe_url); -
@Elltz 我尝试使用
recipe_url.setFocusableInTouchMode(true);但上下文菜单仍然没有出现:/ -
@balajikoduri 我试过这样做,它有效,但它只允许我粘贴或复制,但我希望能够执行所有功能(复制、粘贴、选择、全选)
标签: android android-edittext contextmenu