当前位置: 移动技术网 > IT编程>移动开发>Android > Android仿QQ复制昵称效果的实现方法

Android仿QQ复制昵称效果的实现方法

2019年07月23日  | 移动技术网IT编程  | 我要评论

旅行者 阿豆,剑网3盗兵符,6918结婚记

背景:

在文章中,给出了一种复制qq效果的方案,今天就来讲讲换一种方式实现。主要依赖的是一个开源项目https://github.com/shangmingchao/popuplist

解决办法:

popuplist.java的代码封装的比较完善,用纯java代码实现view效果,不需要使用图片,xml资源文件,引入的话,只需要copy popuplist.java代码到项目工程中。

剩下的就是调用了。这里不分析源码,源码比较简单,只讲如何使用的。

popuplist popuplist = new popuplist(this);
list<string> popupmenuitemlist = new arraylist<>(arrays.aslist("复制qq号"));
popuplist.bind(tvqqnum, popupmenuitemlist, new popuplist.popuplistlistener() {
 @override
 public boolean showpopuplist(view adapterview, view contextview, int contextposition) {
  return true;
 }
 
 @override
 public void onpopuplistclick(view contextview, int contextposition, int position) {
  clipboardmanager cm = (clipboardmanager) getsystemservice(context.clipboard_service);
  clipdata clipdata = clipdata.newplaintext("label", "10001");
  cm.setprimaryclip(clipdata);
 }
});

popuplist popuplist = new popuplist(this);
list<string> popupmenuitemlist = new arraylist<>(arrays.aslist("复制"));
popuplist.bind(tvusername, popupmenuitemlist, new popuplist.popuplistlistener() {
 @override
 public boolean showpopuplist(view adapterview, view contextview, int contextposition) {
  return true;
 }
 
 @override
 public void onpopuplistclick(view contextview, int contextposition, int position) {
  clipboardmanager cm = (clipboardmanager) getsystemservice(context.clipboard_service);
  clipdata clipdata = clipdata.newplaintext("label", "天天");
  cm.setprimaryclip(clipdata);
 }
});

用法很简单。popuplist支持单个,也支持数组形式的结构,如朋友圈点赞的那种效果等。

参考资料:

https://github.com/shangmingchao/popuplist

总结

以上所述是小编给大家介绍的android仿qq复制昵称效果的实现方法,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网