Android文字的複製和粘貼,android文字粘貼

來源:互聯網
上載者:User

Android文字的複製和粘貼,android文字粘貼

Android中提供了簡單的額複製粘貼功能。代碼很簡單

複製文字的代碼:

ClipboardManager cbm= (ClipboardManager) MainActivity.this                 .getSystemService(Context.CLIPBOARD_SERVICE);                  cbm.setText("要複製的文字"); 

粘貼文字的代碼:

ClipboardManager paste = (ClipboardManager) MainActivity.this                 .getSystemService(Context.CLIPBOARD_SERVICE);                 String content=plaster.getText().toString(); 

但是在API11之後 複製粘貼是有差異的,其實就是導包的問題,詳情參見http://www.apkbus.com/android-174549-1-1.html

這裡粘上原文

在前面的項目中有做一個複製粘貼的功能,但是在api11 之後 複製粘貼是有差異的,而且網上的都只有一部分的, 現在分享給大家;
public void onClick(View v) {
                // TODO Auto-generated method stub
                switch (v.getId()) {
                case R.id.top_back:
                        finish();
                        break;
                case R.id.btn_invited_copy:
                        int sdkInt = Build.VERSION.SDK_INT;
                        if (sdkInt > Build.VERSION_CODES.HONEYCOMB) {// api11
                                ClipboardManager copy = (ClipboardManager) ActMyInvitationCode.this
                                                .getSystemService(Context.CLIPBOARD_SERVICE);
                                copy.setText(invitationCode);
                                Toast.makeText(ActMyInvitationCode.this, "邀請碼成功複製到粘貼板",
                                                Toast.LENGTH_SHORT).show();
                        } else if (sdkInt <= Build.VERSION_CODES.HONEYCOMB) {
                                android.text.ClipboardManager copyq = (android.text.ClipboardManager) ActMyInvitationCode.this
                                                .getSystemService(Context.CLIPBOARD_SERVICE);
                                copyq.setText(invitationCode);
                                Toast.makeText(ActMyInvitationCode.this, "邀請碼成功複製到粘貼板",
                                                Toast.LENGTH_SHORT).show();
                        }
                        break;
                }
        }
有的童鞋還沒有看出其中的差別  在api 11之後用的是android.content.ClipboardManager;而在api11之前用的是android.text.ClipboardManager;

】  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.