展現個人分享截圖,效果如圖:你們想作的話,可省略個人佈局,本身隨便定義一個佈局android
先顯示彈出框代碼:ide
//推廣彈框 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; }
彈出框的佈局佈局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/linear_child" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="40dp" android:background="@drawable/rect_greynormal" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/my_tuiguangbg" android:orientation="vertical"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/x40"> <ImageView android:id="@+id/iv_tuiguangclose" android:layout_width="@dimen/x34" android:layout_height="@dimen/x34" android:layout_marginLeft="@dimen/x24" android:src="@drawable/my_tuiguangclose" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingBottom="@dimen/x10" android:text="@string/tuiguangtit" android:textColor="@color/textcolor" android:textSize="@dimen/textsize3" /> <ImageView android:id="@+id/iv_tuiguangshare" android:layout_width="@dimen/x34" android:layout_height="@dimen/x34" android:layout_alignParentRight="true" android:layout_marginRight="@dimen/x24" android:src="@drawable/icon_share" /> </RelativeLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/x20" android:gravity="center" android:text="@string/tuiguang1" android:textColor="@color/stextcolor" android:textSize="@dimen/textsize6" /> <TextView android:id="@+id/tv_zhinan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/x24" android:gravity="center" android:text="@string/tuiguang2" android:textColor="@color/maincolor" android:textSize="@dimen/textsize6" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="@dimen/x70" android:gravity="center" android:orientation="horizontal" android:paddingLeft="@dimen/x24" android:paddingRight="@dimen/x24"> <com.fbx.dushu.utils.CircleImageView android:id="@+id/cir_head" android:layout_width="@dimen/x64" android:layout_height="@dimen/x64" android:src="@drawable/no_touxiang" /> <TextView android:id="@+id/tv_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/x18" android:text="小ba" android:textColor="@color/textcolor" android:textSize="@dimen/textsize6" /> </LinearLayout> <ImageView android:id="@+id/iv_erweima" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="@dimen/x34" android:src="@drawable/my_tuiguangerweima" /> </LinearLayout> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:textSize="@dimen/textsize6" android:text="@string/shareto" android:visibility="gone" android:layout_marginTop="@dimen/x30" android:textColor="@color/white"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="center" android:visibility="gone" android:layout_marginTop="@dimen/x40"> <ImageView android:id="@+id/iv_shareqq" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/x46" android:src="@drawable/my_shareqq"/> <ImageView android:id="@+id/iv_shareweibo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/x46" android:src="@drawable/my_shareweibo"/> <ImageView android:id="@+id/iv_shareweixin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/my_shareweixin"/> </LinearLayout> </LinearLayout> </ScrollView> </RelativeLayout>
彈出框佈局文件的圓邊樣式ui
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 填充顏色 --> <solid android:color="@color/white"></solid> <!-- 線的寬度,顏色灰色 --> <stroke android:width="@dimen/x1" android:color="@color/line_grey"></stroke> <corners android:radius="@dimen/x25"/> </shape>
調用起彈出框url
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("取消分享"); } }); } });
截圖的方法:spa
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; }
這樣就能夠了,最重要的仍是最後截圖的這個方法orm