[英]How can I add custom edittext with custom action for single tap on curser?
I have a custom edittext where I customised it's context menu and add some custom menus to it using the function.我有一个自定义的 edittext,我在其中自定义了它的上下文菜单,并使用该功能向其添加了一些自定义菜单。 Setcustomactionmodecallback();
setcustomactionmodecallback(); This gets triggered whenever select text with double tap or long press but I want it to trigger when I click on curser also.
每当使用双击或长按选择文本时都会触发它,但我希望它在我单击光标时也触发。 If currently I tap on curser it's default action mode gets triggered not my custom one.
如果目前我点击光标,它的默认操作模式将被触发而不是我的自定义模式。
I am new to programming/Android so sorry for mistakes.我是编程/Android 新手,对于错误很抱歉。
I SOLVED THIS I solved this by saving old curser position in OnTouch() method before passing it to super.OnTouch().我解决了这个问题我通过在将 OnTouch() 方法传递给 super.OnTouch() 之前保存旧的光标位置来解决这个问题。 In on Click method of context menu I get new curser position with method getSelectionStart().
在上下文菜单的单击方法中,我使用方法 getSelectionStart() 获得了新的光标位置。 If both are equal then obviously u tapped on curser hence context menu should be shown.
如果两者相等,那么显然你点击了光标,因此应该显示上下文菜单。
I solved this.我解决了这个问题。 In the onTouch method of custom edittext I saved old curser position in private int variable.
在自定义 edittext 的 onTouch 方法中,我将旧光标位置保存在私有 int 变量中。 Before super.ontouch.
在 super.ontouch 之前。 And in onSelection.
并在 onSelection 中。 Changed I compared old selection with new, if both are same then I must have clicked on same position.
更改我将旧选择与新选择进行比较,如果两者相同,那么我必须单击相同的位置。 If I have clicked on same position then I show action menu
如果我点击了相同的位置,那么我会显示操作菜单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.