长按复制TextView


public class MainActivity extends AppCompatActivity {
    private TextView tv1;
    private EditText ed2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv1=(TextView)findViewById(R.id.tv1);
        tv1.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ClipboardManager cmb = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
                cmb.setText(tv1.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
                Toast.makeText(getApplicationContext(),"已经复制",Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    }
}

这样就可以长按textView textView就在系统的粘贴板里边了

你可能感兴趣的:(textview,android)