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

对于列表来说,如果想操作某个列表项,一般会采用长按弹出菜单的形式,默认的上下文菜单比较难看,而QQ的上下文菜单就人性化多了,整个菜单给用户一种气泡弹出的感觉,而且会显示在手指按下的位置,接下来通过本文给大家分享Android仿QQ长按删除弹出框功能,一起看看吧

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

        对于列表来说,如果想操作某个列表项,一般会采用长按弹出菜单的形式,默认的上下文菜单比较难看,而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(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长按删除弹出框功能示例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 移动