android截图并分析所有按钮,Android 部分截图分享

展示我的分享截图,效果如图:大家想做的话,可省略我的布局,自己随便定义一个布局

00e342d77709f0160f7849c866aa894e.png

先显示弹出框代码:

//推广弹框

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;

}

弹出框的布局

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:scrollbars="none">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

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">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/my_tuiguangbg"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="@dimen/x40">

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" />

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" />

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" />

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" />

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" />

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">

android:id="@+id/cir_head"

android:layout_width="@dimen/x64"

android:layout_height="@dimen/x64"

android:src="@drawable/no_touxiang" />

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" />

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" />

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"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:gravity="center"

android:visibility="gone"

android:layout_marginTop="@dimen/x40">

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"/>

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"/>

android:id="@+id/iv_shareweixin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/my_shareweixin"/>

弹出框布局文件的圆边样式

android:shape="rectangle">

android:color="@color/line_grey">

调用起弹出框

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;

}

这样就可以了,最重要的还是最后截图的这个方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值