- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我的目标是拥有一个没有花哨功能的 EditText
,只是用于更轻松地移动光标的文本选择处理程序——因此没有上下文菜单或弹出窗口。
根据 this solution,我通过使用 ActionMode 回调事件禁用了文本编辑功能操作栏的外观(复制/粘贴等)。 .
当字段中存在文本并且在文本中发生单击时,中间的中间文本选择句柄(见下图)仍会出现。伟大的!我想保持这种行为。我不希望在单击文本选择句柄时出现“粘贴”菜单。
我还通过在样式 XML 中设置 android:longClickable="false"
禁用了 EditText 的长按输入。禁用长按可防止在单击并按住鼠标(即长按)时出现“粘贴/替换”菜单,但是当在文本内单击鼠标(单击)时,将出现文本选择句柄,并且当单击文本选择句柄本身,然后出现“粘贴”菜单选项(当剪贴板中有文本时)。这是我试图阻止的。
从源代码中我可以看到,ActionPopupWindow
是 PASTE/REPLACE 选项弹出的内容。 ActionPopupWindow 是公共(public)类android.widget.Editor 中私有(private)抽象类HandleView 中的 protected 变量(mActionPopupWindow)...
没有禁用剪贴板服务或编辑 Android 源代码,有什么方法可以阻止它显示吗?我尝试为 android:textSelectHandleWindowStyle
定义一个新样式,并将 android:visibility
设置为 gone
,但它不起作用(应用程序卡住一段时间,否则它会显示)。
最佳答案
解决方案:在 EditText
中覆盖 isSuggestionsEnabled
和 canPaste
。
为了快速解决,请复制下面的类 - 该类覆盖 EditText
类,并相应地阻止所有事件。
有关坚韧不拔的细节,请继续阅读。
解决方案在于阻止 PASTE/REPLACE 菜单出现在 show()
中。 (未记录的)android.widget.Editor
类的方法。在菜单出现之前,会检查 if (!canPaste && !canSuggest) return;
。作为设置这些变量的基础的两个方法都在 EditText
类中:
isSuggestionsEnabled()
是 public ,因此可能会被覆盖。canPaste()
不是,因此必须被 introducing a function of the same name 隐藏在派生类中。因此,将这些更新合并到一个也有 setCustomSelectionActionModeCallback 的类中,以及 disabled long-click ,这里是防止所有编辑(但仍显示 text selection handler )用于控制光标的完整类:
package com.cjbs.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
/**
* This is a thin veneer over EditText, with copy/paste/spell-check removed.
*/
public class NoMenuEditText extends EditText
{
private final Context context;
/** This is a replacement method for the base TextView class' method of the same name. This
* method is used in hidden class android.widget.Editor to determine whether the PASTE/REPLACE popup
* appears when triggered from the text insertion handle. Returning false forces this window
* to never appear.
* @return false
*/
boolean canPaste()
{
return false;
}
/** This is a replacement method for the base TextView class' method of the same name. This method
* is used in hidden class android.widget.Editor to determine whether the PASTE/REPLACE popup
* appears when triggered from the text insertion handle. Returning false forces this window
* to never appear.
* @return false
*/
@Override
public boolean isSuggestionsEnabled()
{
return false;
}
public NoMenuEditText(Context context)
{
super(context);
this.context = context;
init();
}
public NoMenuEditText(Context context, AttributeSet attrs)
{
super(context, attrs);
this.context = context;
init();
}
public NoMenuEditText(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
this.context = context;
init();
}
private void init()
{
this.setCustomSelectionActionModeCallback(new ActionModeCallbackInterceptor());
this.setLongClickable(false);
}
/**
* Prevents the action bar (top horizontal bar with cut, copy, paste, etc.) from appearing
* by intercepting the callback that would cause it to be created, and returning false.
*/
private class ActionModeCallbackInterceptor implements ActionMode.Callback
{
private final String TAG = NoMenuEditText.class.getSimpleName();
public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; }
public void onDestroyActionMode(ActionMode mode) {}
}
}
我已经在 Android v4.4.2 和 v4.4.3 中对此进行了测试。
关于android - 编辑文本 : Disable Paste/Replace menu pop-up on Text Selection Handler click event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27869983/
所以下面的内容让我很困惑。 #!/usr/bin/python test = [0, 0, 0, 1, 2, 3, 4, 5, 6] test1 = [0, 0, 0, 1, 2, 3, 4, 5,
这个问题是这个问题的后续问题: deque.popleft() and list.pop(0). Is there performance difference? 在 Python 中,我可以使用 .
我正在使用 bootstrap v2.2.2。我尝试了其他一些方法(即: close popover outside popover but inside stay open 和 How to dis
我正在用 Python 创建提交后脚本并使用子进程调用 git 命令。 在我的脚本中,我想在运行某些命令之前存储所有更改,然后将它们 pop 。问题是,如果没有任何东西可以存储,stash pop 会
我有一个嵌入在 UINavigationController 中的 UITableViewController,我正在尝试将 Peek & Pop 实现到 TableView 中。我的“窥视”部分工作
我的 Windows 机器上安装了 Cygwin、msysgit 和 TortoiseGit。我正在为 Cygwin 编写一个脚本,该脚本通过 ssh 将 git 推送到远程机器: git push
我在 Jenkins 中使用groovy,并且我需要这个字符串来获取其中的最后一个单词。假设字符串是 STATUS = "EXECUTE SIT" 。所以我所做的就是分割字符串,这样我就会得到一个数组
本文是不太具体的问题的后续/重新表述 Is it possible to have a hyperlink inside {content:"..."}? . 用户 Naeem Shaikh ,非常感
Navigator.of(context).pop 和 Navigator.pop(context) 有什么区别? 对我来说两者似乎都在做同样的工作,实际的区别是什么。一个被弃用了吗? 最佳答案 Na
这可能吗?我想要一个更简单的命令来 git stash pop stash@{13} 其中 stash@{13} 只是 last 意思是“最后的存储在列表上”或“最古老的藏品”。 我知道我可以为 gi
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
Visual Studio 2019 中用于 GIT 存储的以下命令有什么区别? 分阶段 pop 和恢复 (--index) 全部 pop 为未暂存状态 使用https://visualstudio.
我想弹出模型的最后一层。所以我使用了 tf.keras.layers.pop(),但它不起作用。 base_model.summary() base_model.layers.pop() base_m
我想使用 navigator.pop 将值从第 2 页传递到第 1 页,并使用 initstate 中的新值刷新或重新加载我的第 1 页或任何其他解决方法? 我能够在第一页中获取这些值,但无法使用 i
pop 函数的文档说: user> (doc pop) ------------------------- clojure.core/pop ([coll]) For a list or queu
我有以下点击处理程序,当点击它时,我从 handsontable 中提取一个数组然后从数组中删除最后一个元素,并将新数组传递给 ajax post。问题是,如果我再次单击该按钮,它将从数组中删除另一个
我在mailmuch中制作了表单并从中获取了代码,我添加到网页并使用href,当用户单击显示弹出窗口时显示表单。没关系 show popup 但是现在我有ajax请求,我希望在ajax返回成功时显示此
我目前正在学习 Python 中的 pop() 函数并有一个问题。 >>> a = [1,2,3,4] >>> a.pop(3) #or a.pop() 4 >>> print(a) [1,2,3]
我目前正在学习 Python 中的 pop() 函数并有一个问题。 >>> a = [1,2,3,4] >>> a.pop(3) #or a.pop() 4 >>> print(a) [1,2,3]
我可以将对象$push编码到Mongo数组上,如下所示: db.foo.update({},{$push:{bar:3}}) 但是我找不到一种语法,可以让我对列表中的最后一项进行$pop编码。 我已经
我是一名优秀的程序员,十分优秀!