本文同步自http://javaexception.com/archives/77

背景:

上一篇文章中,给出了一种复制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

最新文章

  1. 关于SubSonic3.0插件使用SqlQuery或Select查询时产生的System.NullReferenceException异常修复
  2. Session一次错误记录
  3. 禁止在 .NET Framework 中执行用户代码。启用 &quot;clr enabled&quot; 配置选项
  4. Codeforces Round #221 (Div. 2) C. Divisible by Seven(构造 大数除法 )
  5. 【POJ】1692 Crossed Matchings
  6. 简单的批量读取外部insert文并插入DB
  7. [Hapi.js] Serving static files
  8. Oracle监听静态注册和动态注册
  9. 将文件从数据库(MySQL)中进行读取
  10. HTML5初步了解
  11. ASP.NET CORE小试牛刀:干货(完整源码)
  12. 关于docker使用的几个小问题(二)
  13. Hibernate开发文档
  14. Redis 集群的安装
  15. flask之入门
  16. Spring AutoWire
  17. HSSFClientAnchor 参数说明
  18. MySQL的1067错误解决方法
  19. FireDac 组件说明二
  20. English trip -- VC(情景课)2 D Reading

热门文章

  1. 可用性的维度(5E)
  2. js时间小总结
  3. javascript函数,构造函数。js对象和json的区别。js中this指向问题
  4. [shell 编程] if [ $# -eq 0 ]该语句是什么含义?
  5. lykops运维自动化
  6. MacBook安装office
  7. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.9. 配置用户等效性(可选项)
  8. flume分布式日志收集系统操作
  9. (转)spring boot实战(第三篇)事件监听源码分析
  10. Node.js 解析gzip网页(https)