如何将文本复制到剪切板中的Andr​​oid? [英] How to Copy Text to Clip Board in Android?

查看:172
本文介绍了如何将文本复制到剪切板中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何复制文本present在一个特定的TextView到剪贴板当按钮是pressed? 感谢名单:)

Can anybody please tell me how to copy the text present in a particular textview to clipboard when a button is pressed? Thanx :)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainpage);
    textView = (TextView) findViewById(R.id.textview);
    copyText = (Button) findViewById(R.id.bCopy);
    copyText.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            String getstring = textView.getText().toString();

            //Help to continue :)





        }
    });
}

}

我要复制的文本中的TextView TextView中到剪贴板时,按钮BCOPY是pressed!请你帮助...

I want to copy the Text in TextView textView to clipboard when the Button bCopy is pressed! Please do help...

推荐答案

使用<一个href="http://developer.android.com/reference/android/content/ClipboardManager.html">ClipboardManager

 ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
 ClipData clip = ClipData.newPlainText(label, text);
 clipboard.setPrimaryClip(clip);

检查该<一href="http://developer.android.com/reference/android/content/ClipData.html#newPlainText%28java.lang.CharSequence,%20java.lang.CharSequence%29">link

这篇关于如何将文本复制到剪切板中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆