作者: 牙叔
使用场景:
引导新用户, 学习软件的使用方法
效果展示:
仅为演示功能, 未做美化
实现步骤
- 等待页面布局加载完毕
ui.guide.click(function () { log("开启新手引导"); setTimeout(function () { 新手引导(); }, 500); });
- 截图
function screenCapture(activity) { log("screenCapture"); // 获取windows中最顶层的view view = activity.getWindow().getDecorView(); view.buildDrawingCache(); // 获取状态栏高度 rect = new Rect(); view.getWindowVisibleDisplayFrame(rect); statusBarHeights = rect.top; display = activity.getWindowManager().getDefaultDisplay(); // 获取屏幕宽和高 widths = display.getWidth(); heights = display.getHeight(); // 允许当前窗口保存缓存信息 view.setDrawingCacheEnabled(true); // 去掉状态栏 let bmp = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeights, widths, heights - statusBarHeights); // 销毁缓存信息 view.destroyDrawingCache(); return bmp; }
- 添加一个
popWindow
, 里面只有一个<img>
let contentView = ui.inflate( <vertical> <img id="img" layout_width="match_parent" layout_height="match_parent"></img> </vertical>, null, false ); let mPopWindow = new PopupWindow( contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true );
- 画一层遮罩
canvas.drawARGB(200, 125, 125, 125);
- 指定按钮处画边框
paint.setStyle(Paint.Style.STROKE); //空心矩形框 paint.setStrokeWidth(20); paint.setColor(colors.parseColor("#0000ff")); canvas.drawRect(data.left, data.top, data.right, data.bottom, paint);
- 指定按钮从图片中裁剪出来
let clip = images.clip(img, data.left, data.top, data.right - data.left, data.bottom - data.top); let smallBitmap = clip.getBitmap();
- 画指定按钮
canvas.drawBitmap(smallBitmap, data.left, data.top, paint);
- 添加文字
paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(70); paint.setStyle(Paint.Style.FILL); paint.setColor(colors.parseColor("#f000ff")); canvas.drawText(data.introduction, data.left + parseInt((data.right - data.left) / 2), data.bottom + 100, paint);
img
控件加载图片
imgView.attr("src", "file://" + compositeImgpath);