本文实例讲述了Android编程实现自定义分享列表ACTION_SEND功能的方法。分享给大家供大家参考,具体如下:
看到最近都在做自定义的东西,因为比较灵活,还可以摆脱系统自身不怎么漂亮的UI,(大家都懂得)所以自己也做了下自定义的分享列表,用PopupWindow的方式弹出。
先上效果图:
1、布局:
popup_share.xml
popup_share_item.xml
2、查询手机内所有支持分享的应用列表
public ListgetShareApps(Context context) { List mApps = new ArrayList (); Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); // intent.setType("**"); //这里就是组织内容了, shareIntent.putExtra(Intent.EXTRA_TEXT, "测试,这里发送推广地址"); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); DetailExchangeActivity.this.startActivity(shareIntent); } }); sharePopupWindow = new PopupWindow(view, (int)(160 * density), LinearLayout.LayoutParams.WRAP_CONTENT); } //使其聚焦 sharePopupWindow.setFocusable(true); //设置允许在外点击消失 sharePopupWindow.setOutsideTouchable(true); // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景 sharePopupWindow.setBackgroundDrawable(new BitmapDrawable()); //xoff,yoff基于anchor的左下角进行偏移。正数表示下方右边,负数表示(上方左边) //showAsDropDown(parent, xPos, yPos); sharePopupWindow.showAsDropDown(parent, -5, 5); }
注:ShareCustomAdapter自己建一个就行了。(有一个图标和一个分享的名)
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。



