Android:使用 LinkMovementMethod 编辑文本
我基本上想了解 LinkMovementMethod 类。我在编辑文本中有一个图像,需要可单击。所以我使用 LinkMovementMethod.getInstance 来编辑文本。但由于此 LinkMovementMethod 对象,用于编辑文本(如复制、剪切、粘贴)的上下文菜单(长按)选项不可见。我也无法将光标定位在编辑文本中。不知何故,光标隐藏了。
在编辑文本中使用 LinkMovementMethod 是正确的方法吗?还是有必要为光标和上下文菜单问题编写自定义 LinkMovementMethod 类。
EditText editText = (EditText)findViewById(R.id.text);
editText.setMovementMethod(LinkMovementMethod.getInstance());
-问候, 罗恩..
I basically wants to understand about LinkMovementMethod class. I am having an Image inside edit text that needs to be clickable. So I used LinkMovementMethod.getInstance for edit text. But because of this LinkMovementMethod object the context menu(long press) options for edit text like copy, cut, paste are not visible. Also i am not able to position cursor in edit text. Somehow the cursor is hiding.
Is it the correct approach to use LinkMovementMethod in edit text or is it necessary to write a custom LinkMovementMethod class for the cursor and context menu problem.
EditText editText = (EditText)findViewById(R.id.text);
editText.setMovementMethod(LinkMovementMethod.getInstance());
-Regards,
Ron..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应将 LinkMovementMethod 与可编辑文本一起使用。 LinkMovementMethod 是一种移动方法,可让您在链接之间移动...这不是您想要的文本编辑器,因为您应该使用移动光标进行编辑的移动方法。
您希望如何处理可编辑文本中的链接?当您有可编辑的文本时,点击文本会将光标置于该点进行编辑。它不会打开链接。这是两个相互矛盾的事情。如果您想要一些其他行为,您将需要自定义文本视图来执行一些特殊操作,并弄清楚如何消除编辑链接文本和打开它之间的歧义(例如,Google Docs 会向您显示一个弹出窗口)如果您不想编辑它,请选择将其打开)。但是您需要自己编写代码,在当前框架中没有神奇的内置东西可以实现这一点。
You shouldn't use LinkMovementMethod with editable text. LinkMovementMethod is a movement method that lets you move around between links... which is not what you want for a text editor, since you should be using the movement method that moves the cursor around for editing.
What do you expect to do with links in editable text? When you have editable text, tapping on the text puts the cursor at that point to edit it. It doesn't open the link. These are two conflicting things. If you want to have some other behavior, you will need to customize the text view to do something special and figure out how you are going to disambiguate between editing the link text and opening it (for example Google Docs shows you a pop-up to select to open it if you don't want to edit it). But you will need to code this yourself, there is no magic built-in thing that implements this in the current framework.
一种方法是
扩展EditText
One ways is
extends EditText