• 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;

    】  
  • 相关阅读:
    ASP.NET程序中常用的三十三种代码[1]
    window.showModalDialog使用手册
    ASP函数详解
    ASP.NET程序中常用的三十三种代码[2]
    Session对象的清空
    Css不朽的经典—3D文字特效
    IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
    ASP.NET程序中常用的三十三种代码[3]
    平面设计常用制作尺寸
    Work with a file upload and download controls2
  • 原文地址:https://www.cnblogs.com/dongweiq/p/4383478.html
Copyright © 2020-2023  润新知