1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android 禁用剪切板_Android EditText禁止复制粘贴

android 禁用剪切板_Android EditText禁止复制粘贴

时间:2021-08-21 21:50:56

相关推荐

android 禁用剪切板_Android EditText禁止复制粘贴

1,自定义EditTextpackagecom.example.ui;importandroid.annotation.SuppressLint;importandroid.content.Context;importandroid.util.AttributeSet;importandroid.view.ActionMode;importandroid.view.Menu;importandroid.view.MenuItem;importandroid.widget.EditText;

@SuppressLint("NewApi")public class NoMenuEditText extendsEditText {private finalContext 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.

*

*@returnfalse*/

booleancanPaste() {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.

*

*@returnfalse*/@Overridepublic booleanisSuggestionsEnabled() {return false;

}publicNoMenuEditText(Context context) {super(context);this.context =context;

init();

}publicNoMenuEditText(Context context, AttributeSet attrs) {super(context, attrs);this.context =context;

init();

}public NoMenuEditText(Context context, AttributeSet attrs, intdefStyle) {super(context, attrs, defStyle);this.context =context;

init();

}private voidinit() {this.setCustomSelectionActionModeCallback(newActionModeCallbackInterceptor());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 implementsActionMode.Callback {private final String TAG = NoMenuEditText.class.getSimpleName();public booleanonCreateActionMode(ActionMode mode, Menu menu) {return false;

}public booleanonPrepareActionMode(ActionMode mode, Menu menu) {return false;

}public booleanonActionItemClicked(ActionMode mode, MenuItem item) {return false;

}public voidonDestroyActionMode(ActionMode mode) {

}

}

}2,在layout.xml文件中这样使用

android:id="@+id/ddd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="禁止复制粘贴" />

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。