简体   繁体   English

如何为单击光标添加带有自定义操作的自定义编辑文本?

[英]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.

相关问题 如何创建 Notification.Action 并将其添加到自定义通知 - How can I create a Notification.Action and add it to a custom notification 在Android(在JB上),如何向自定义丰富通知添加操作? - In Android (on JB), how can I add an action to a custom rich notification? 在Android中点击EditText时如何查看自定义软键盘? - How to view custom softkeyboard while tap on EditText in android? 如何向自定义浮动操作按钮添加图标和自定义textView - how can I add an icon and a custom textView to a custom floating action button 如何将EditText中的值添加到自定义ListView中? - How do I add values from EditText to a custom ListView? 如何使用我的自定义 ListView 访问 EditText - How can I access an EditText withing my custom ListView 如何制作看起来像这样的自定义Holo EditText - How can i make a custom Holo EditText that looks like this one 如何制作这种类型的自定义EditText UI? - How can I make this type of custom EditText UI? 如何在EditText中存储自定义对象/属性? - How can I store custom object/attribute in an EditText? 如何在Android中使用自定义按钮实现自定义操作栏? - How can I implement custom Action Bar with custom buttons in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM