Android仿QQ复制昵称效果2
2024-08-26 12:34:14
本文同步自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
最新文章
- 关于SubSonic3.0插件使用SqlQuery或Select查询时产生的System.NullReferenceException异常修复
- Session一次错误记录
- 禁止在 .NET Framework 中执行用户代码。启用 ";clr enabled"; 配置选项
- Codeforces Round #221 (Div. 2) C. Divisible by Seven(构造 大数除法 )
- 【POJ】1692 Crossed Matchings
- 简单的批量读取外部insert文并插入DB
- [Hapi.js] Serving static files
- Oracle监听静态注册和动态注册
- 将文件从数据库(MySQL)中进行读取
- HTML5初步了解
- ASP.NET CORE小试牛刀:干货(完整源码)
- 关于docker使用的几个小问题(二)
- Hibernate开发文档
- Redis 集群的安装
- flask之入门
- Spring AutoWire
- HSSFClientAnchor 参数说明
- MySQL的1067错误解决方法
- FireDac 组件说明二
- English trip -- VC(情景课)2 D Reading
热门文章
- 可用性的维度(5E)
- js时间小总结
- javascript函数,构造函数。js对象和json的区别。js中this指向问题
- [shell 编程] if [ $# -eq 0 ]该语句是什么含义?
- lykops运维自动化
- MacBook安装office
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.9.	配置用户等效性(可选项)
- flume分布式日志收集系统操作
- (转)spring boot实战(第三篇)事件监听源码分析
- Node.js 解析gzip网页(https)