你的位置:首页 > 操作系统

[操作系统]android EditText禁止复制粘贴完整代码


<!-- 定义基础布局LinearLayout --><LinearLayout ="http://schemas.android.com/apk/res/android"  ="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">  <!-- 定义TextView控件 -->  <EditText    android:id="@+id/Et"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="禁止复制粘贴"    android:longClickable="false"    /></LinearLayout>

package com.example.yanlei.yl2;import android.content.ClipboardManager;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.ActionMode;import android.view.Menu;import android.view.MenuItem;import android.widget.EditText;public class MainActivity extends AppCompatActivity {  EditText Et;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState); // 调用父类的onCreate方法    // 通过setContentView方法设置当前页面的布局文件为activity_main    setContentView(R.layout.activity_main);    Et=(EditText)findViewById(R.id.Et);    Et.setCustomSelectionActionModeCallback(new ActionMode.Callback()    {      @Override      public boolean onPrepareActionMode(ActionMode mode, Menu menu){        return false;      }      @Override      public void onDestroyActionMode(ActionMode mode){      }      @Override      public boolean onCreateActionMode(ActionMode mode, Menu menu){        return false;      }      @Override      public boolean onActionItemClicked (ActionMode mode, MenuItem item){        return false;      }    });  }}