展示我的分享截图,效果如图:大家想做的话,可省略我的布局,自己随便定义一个布局
先显示弹出框代码:
//推广弹框public static View showTuiguangDialog(Context contxt,String headpath, String userName,final TuiguangDiaClick comClick) { LayoutInflater inflaterDl = LayoutInflater.from(contxt); RelativeLayout layout = (RelativeLayout) inflaterDl.inflate(R.layout.item_tuiguangwindow, null); final Dialog dialog = new AlertDialog.Builder(contxt).create(); dialog.setCancelable(false); dialog.show(); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.getWindow().setContentView(layout); LinearLayout linear_child = (LinearLayout)layout.findViewById(R.id.linear_child); ImageView iv_close = (ImageView)layout.findViewById(R.id.iv_tuiguangclose); TextView tv_zhinan = (TextView) layout.findViewById(R.id.tv_zhinan); CircleImageView cir_head = (CircleImageView) layout.findViewById(R.id.cir_head); TextView tv_username = (TextView) layout.findViewById(R.id.tv_username); ImageView iv_erweima = (ImageView)layout.findViewById(R.id.iv_erweima); ImageView iv_tuiguangshare = (ImageView)layout.findViewById(R.id.iv_tuiguangshare); if (!headpath.equals("")) { if (headpath.contains("http")) { ImageUtils.GlideShowImageAsBitmap(contxt, headpath, cir_head, R.drawable.no_touxiang); } else { ImageUtils.GlideShowImageAsBitmap(contxt, BaseUrlUtils.BaseUrl + headpath, cir_head, R.drawable.no_touxiang); } }else { cir_head.setImageResource(R.drawable.no_touxiang); } if(!userName.equals("")) { tv_username.setText(userName); } iv_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); tv_zhinan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(null !=comClick){ comClick.topClick(); } dialog.dismiss(); } }); iv_tuiguangshare.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { if (null != comClick) { comClick.onRightClick(); } dialog.dismiss(); } }); return linear_child;}
弹出框的布局
弹出框布局文件的圆边样式
调用起弹出框
private View myView;myView = WinDialog.showTuiguangDialog(context, headImg, username, new TuiguangDiaClick() { @Override public void topClick() { //指南 gotoActivity(TuiguangActivity.class); } @Override public void onRightClick() { Bitmap url = takeScreenShot(myView); ShareUtils.shareQQWXPic((MainActivity) context, url, new UMShareListener() { @Override public void onStart(SHARE_MEDIA share_media) { UIUtils.showToastSafe("正在启动分享..."); } @Override public void onResult(SHARE_MEDIA share_media) { UIUtils.showToastSafe("分享成功"); } @Override public void onError(SHARE_MEDIA share_media, Throwable throwable) { } @Override public void onCancel(SHARE_MEDIA share_media) { UIUtils.showToastSafe("取消分享"); } }); }});
截图的方法:
public Bitmap takeScreenShot(View view) { Bitmap overlay = null; int width = view.getMeasuredWidth(); int height = view.getMeasuredHeight(); if (width > 0 && height > 0) { overlay = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas cvs = new Canvas(overlay); view.draw(cvs); } return overlay;}
这样就可以了,最重要的还是最后截图的这个方法