android仿淘口令复制弹出框功能


@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);
}
});

下载说明:
1、本站所有资源均从互联网上收集整理而来,仅供学习交流之用,因此不包含技术服务请大家谅解!
2、本站不提供任何实质性的付费和支付资源,所有需要积分下载的资源均为网站运营赞助费用或者线下劳务费用!
3、本站所有资源仅用于学习及研究使用,您必须在下载后的24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担!
4、本站站内提供的所有可下载资源,本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发),但本站不保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug!如有链接无法下载、失效或广告,请联系客服处理!
5、本站资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您的合法权益,请立即告知本站,本站将及时予与删除并致以最深的歉意!
6、如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
7、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务!
8、请您认真阅读上述内容,注册本站用户或下载本站资源即您同意上述内容!
原文链接:https://www.dandroid.cn/5911,转载请注明出处。
0

评论0

显示验证码
没有账号?注册  忘记密码?