gpt4 book ai didi

android - 使用屏幕键盘捕获 Activity 屏幕

转载 作者:行者123 更新时间:2023-11-29 21:49:34 25 4
gpt4 key购买 nike

我正在尝试在 Android 上捕获我的 Activity 屏幕。我正在使用下面的代码:

View root = this.activity.getWindow().getDecorView().getRootView();

Bitmap b = Bitmap.createBitmap(root.getWidth(), root.getHeight(), Config.RGB_565);
Canvas c = new Canvas(b);
root.draw(c);

if (b != null && !b.isRecycled()) {
this.screen = Bitmap.createBitmap(b);
}

如果屏幕键盘弹出,那么我在 this.screen 中只有 Activity 窗口的可见部分,其余部分是空白的。

有什么方法可以获取我的应用程序的屏幕截图,包括屏幕键盘下方的部分?

最佳答案

很抱歉让您失望了,但如果没有外部帮助,这是无法完成的。键盘根本不是您的应用程序布局的一部分。

您的“最外层” View 是您已经捕捉到的 DecorView。就此技术而言。

编辑:我现在不能尝试,但试一试:

View topmost = ((ViewGroup)
ctx.getWindow().getDecorView().findViewById(android.R.id.content)
).getChildAt(0);

topmost.setDrawingCacheEnabled(true);

Bitmap screenshot = topmost.getDrawingCache();

关于android - 使用屏幕键盘捕获 Activity 屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14778199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com