简体   繁体   English

如何使用显示的警报对话框制作活动的屏幕截图?

[英]How to make a screenshot of the activity with alert dialog shown?

I use this code to make a screenshot. 我使用此代码制作屏幕截图。 However, when I try to call it from the dialog (once user clicked the neutral button or when dialog.show() is called) - the dialog itself is not captured. 但是,当我尝试从对话框中调用它时(用户单击中性按钮或调用dialog.show()时)-对话框本身未捕获。 When (or where) should I use this code to capture the dialog also? 我应何时(或在何处)使用此代码捕获对话框?

Maybe extending Dialog and override onAttachedToWindow method to call your screenshot method from there would work. 也许扩展Dialog并覆盖onAttachedToWindow方法以从那里调用您的屏幕截图方法就可以了。 Something like this.- 像这样-

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    takeScreenshot();
}

The code you are using uses drawing of root View to bitmap. 您正在使用的代码将根视图的图形绘制为位图。 Dialogs, Toasts and other extra windows have different View roots, therefore they do not appear in the screenshot. 对话框,Toast和其他窗口的视图根目录不同,因此它们不会出现在屏幕截图中。

Try out this library: https://github.com/jraska/Falcon it can solve your problem. 试试这个库: https : //github.com/jraska/Falcon它可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM