源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-03-18 01:24 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android仿QQ长按删除弹出框功能示例
  废话不说,先看一下效果图,如果大家感觉不错,请参考实现代码: [img]http://files.jb51.net/file_images/article/201703/201703091007053.png[/img] [img]http://files.jb51.net/file_images/article/201703/201703091007054.png[/img] [img]http://files.jb51.net/file_images/article/201703/201703091007055.png[/img] [img]http://files.jb51.net/file_images/article/201703/201703091007056.png[/img]         对于列表来说,如果想操作某个列表项,一般会采用长按弹出菜单的形式,默认的上下文菜单比较难看,而QQ的上下文菜单就人性化多了,整个菜单给用户一种气泡弹出的感觉,而且会显示在手指按下的位置,而技术实现我之前是使用[b]popupWindow[/b]和[b]RecyclerView[/b]实现的,上面一个[b]RecyclerView[/b],下面一个小箭头ImageView,但后来发现没有必要,而且可定制化也不高,还是使用多个TextView更好一点。         我封装了一下,只需要一个PopupList.Java文件。源码放在了Git上,git地址: [url=https://github.com/shangmingchao/PopupList]https://github.com/shangmingchao/PopupList[/url]         使用方式,很简单:         只需要调用该方法即可完成绑定:
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长按删除弹出框功能示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部