当前位置: 移动技术网 > IT编程>移动开发>Android > Android仿QQ长按删除弹出框功能示例

Android仿QQ长按删除弹出框功能示例

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

红楼梦之十二金钗游戏,计算机文化,金俞铉

  废话不说,先看一下效果图,如果大家感觉不错,请参考实现代码:

        对于列表来说,如果想操作某个列表项,一般会采用长按弹出菜单的形式,默认的上下文菜单比较难看,而qq的上下文菜单就人性化多了,整个菜单给用户一种气泡弹出的感觉,而且会显示在手指按下的位置,而技术实现我之前是使用popupwindowrecyclerview实现的,上面一个recyclerview,下面一个小箭头imageview,但后来发现没有必要,而且可定制化也不高,还是使用多个textview更好一点。

        我封装了一下,只需要一个popuplist.java文件。源码放在了git上,git地址:

https://github.com/shangmingchao/popuplist

        使用方式,很简单:

        只需要调用该方法即可完成绑定:

popuplist popuplist = new popuplist(); 
popuplist.init(context, view, popupmenuitemlist, onpopuplistclicklistener); 

        例子:

lv_main = (listview) findviewbyid(r.id.lv_main); 
mdataadapter = new arrayadapter<string>(this, android.r.layout.simple_expandable_list_item_1, mdatalist); 
lv_main.setadapter(mdataadapter); 
popupmenuitemlist.add(getstring(r.string.copy)); 
popupmenuitemlist.add(getstring(r.string.delete)); 
popupmenuitemlist.add(getstring(r.string.share)); 
popupmenuitemlist.add(getstring(r.string.more)); 
popuplist popuplist = new popuplist(); 
popuplist.init(this, lv_main, popupmenuitemlist, new popuplist.onpopuplistclicklistener() { 
 @override 
 public void onpopuplistclick(view contextview, int contextposition, int position) { 
 toast.maketext(mainactivity.this, contextposition + "," + position, toast.length_long).show(); 
 } 
}); 
imageview indicator = new imageview(this); 
indicator.setimageresource(r.drawable.popuplist_default_arrow); 
popuplist.setindicatorview(indicator); 
popuplist.setindicatorsize(dp2px(16), dp2px(8)); 

以上所述是小编给大家介绍的android仿qq长按删除弹出框功能示例,希望对大家有所帮助

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

相关文章:

验证码:
移动技术网