我正在截屏如下:
public static Bitmap takeScreenshot(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width,
height - statusBarHeight);
view.destroyDrawingCache();
return bitmap2;
}
但是我的布局中有一个 Edittext。我单击它并弹出键盘,但屏幕截图不包含使用这种方式的键盘。如何以编程方式截取屏幕截图也可以捕获键盘?