<!--defining the base layout linearlayout -<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"android:orientation= "vertical"> <!--Defining TextView Controls - <EditTextAndroid:id= "@+id/et"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Prohibit copy and paste"android:longclickable= "false" /></LinearLayout>
Packagecom.example.yanlei.yl2;ImportAndroid.content.ClipboardManager;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.ActionMode;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.widget.EditText; Public classMainactivityextendsappcompatactivity {EditText Et; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);//call the OnCreate method of the parent class//set the current page's layout file to Activity_main by using the Setcontentview methodSetcontentview (R.layout.activity_main); Et=(EditText) Findviewbyid (r.id.et); Et.setcustomselectionactionmodecallback (NewActionmode.callback () {@Override Public BooleanOnprepareactionmode (actionmode Mode, menu menu) {return false; } @Override Public voidOndestroyactionmode (Actionmode mode) {} @Override Public BooleanOncreateactionmode (actionmode Mode, menu menu) {return false; } @Override Public Booleanonactionitemclicked (actionmode mode, MenuItem item) {return false; } }); }}
Android EditText prohibit copy and paste full code