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<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,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长按删除弹出框功能示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

以上是来客网为你收集整理的Android仿QQ长按删除弹出框功能示例全部内容,希望文章能够帮你解决Android仿QQ长按删除弹出框功能示例所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。