android 截图时,获取不到AlertDialog?

galibujianbusana 2017-02-06 04:00:29
求助,有什么方法,截图可以截取到AlertDialog?下面的无法截取到AlertDialog
private void screenshot1(String Strname)
{
/**
* Strname--如 2.png 需要带后缀
* */
// 获取屏幕
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bmp = dView.getDrawingCache();
if (bmp != null)
{
try {
// 获取内置SD卡路径
String sdCardPath = Environment.getExternalStorageDirectory().getPath();
// 图片文件路径

File filedir = new File(sdCardPath + File.separator + "AA");
if (!filedir.exists()) {
filedir.mkdirs();
}
File saveFile = new File(filedir, Strname);
FileOutputStream outStream1 = new FileOutputStream(saveFile);
System.out.println(outStream1.toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
outStream1.write(byteArray);
outStream1.close();
Toast.makeText(Zhuye_Activity.this,"截图保存成功",Toast.LENGTH_SHORT).show();
dView.setDrawingCacheEnabled(false); // 这里不设置false,那么下次截图还是上次的图片
} catch (Exception e) {
}
}
}

...全文
117 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
galibujianbusana 2017-11-17
  • 打赏
  • 举报
回复
^

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧