博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android EditText禁止复制粘贴
阅读量:5989 次
发布时间:2019-06-20

本文共 2211 字,大约阅读时间需要 7 分钟。

1,自定义EditTextpackage com.example.ui;import android.annotation.SuppressLint;import android.content.Context;import android.util.AttributeSet;import android.view.ActionMode;import android.view.Menu;import android.view.MenuItem;import android.widget.EditText;  @SuppressLint("NewApi")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*/@Overridepublic 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) {}}}2,在layout.xml文件中这样使用

 

转载地址:http://xunlx.baihongyu.com/

你可能感兴趣的文章
SVN中分支与合并
查看>>
百度定位---基础定位
查看>>
使用Docker创建JavaWeb运行环境(亲测)
查看>>
java加密解密和证书的demo
查看>>
How to open vmware view database(ADAM)
查看>>
数人云|PaaS Innovation 2017 云计算大会那么多,关心PaaS只有它
查看>>
centos6.5 升级gclib2.1.2 到2.14
查看>>
IOS UIFont 所有字体预览
查看>>
Android --- App Widget 开发
查看>>
Maven国内镜像加速
查看>>
一:NIO
查看>>
Android进阶之使用第三方平台ShareSDK实现新浪微博的一键分享功能
查看>>
angular 中指令参数 required 说明
查看>>
三个练习题帮助理解“精度" "召回率""F1值"
查看>>
使用JavaMail发送邮件
查看>>
nginx 配置文件夹浏览
查看>>
Mysql 数据库备份
查看>>
用户界面控件的王者之争:Kendo UI vs DevExpress(一)
查看>>
indows下使用TortoiseGit管理github工程
查看>>
Linux ssh工具之xshell
查看>>