# android仿淘口令复制弹出框功能 站点:答源(https://www.dandroid.cn/) 原文:https://www.dandroid.cn/archives/5911 Canonical:https://www.dandroid.cn/archives/5911 作者:dandroid001 发布日期:2019-01-17 最后更新:2019-01-17 07:13 分类:Android应用源码 / 系统相关 内容类型:post 说明:本页是原文的纯文本镜像,供大模型与检索器完整读取;不含导航、广告、付费框。引用请以上方「原文」链接为准。 ## 摘要 类似从微信里面复制的淘宝分享链接弹窗效果 ## 正文 @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); ClipboardManager mClipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); Log.e("Copylistenerdemo", mClipboardManager.getPrimaryClip().getItemAt(0).getText().toString()); } 创建一个Service在后台运行,在Service管理粘贴板服务: mClipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); mClipboardManager.addPrimaryClipChangedListener(mPrimaryClipChangedListener); 在onPrimaryClipChanged()做想要的事情,例如弹出框: LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View floatView = layoutInflater.inflate(R.layout.floater, null); final WindowManager mWindowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); LayoutParams params = new WindowManager.LayoutParams(); params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;//系统内部错误提示,显示于所有内容之上 params.format = PixelFormat.RGBA_8888; params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; //当窗口可以获得焦点(没有设置FLAG_NOT_FOCUSALBE选项)时,仍然将窗口范围之外的点设备事件(鼠标、触摸屏)发送给后面的窗口处理 params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.gravity = Gravity.LEFT | Gravity.TOP; params.x = 0; params.y = 0; mWindowManager.addView(floatView, params); ObjectAnimator animatorShow = ObjectAnimator.ofFloat(floatView, "alpha", 0.0f,1.0f); animatorShow.setDuration(500); animatorShow.start(); ObjectAnimator animatorHide = ObjectAnimator.ofFloat(floatView, "alpha", 1.0f,0.0f); animatorHide.setDuration(500); animatorHide.setStartDelay(3000); animatorHide.start();   floatView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainService.this, "点击淘口令", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(MainService.this, xxActivity.class); startActivity(intent); } }); --- 由 答源 DAN 底座 1.4.1 生成 · 2026-11-10T07:06:18+00:00