我使用这些行来截取我的 Activity :
View toppest = ((ViewGroup) ctx.getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0);
toppest.setDrawingCacheEnabled(true);
Bitmap bmap = toppest.getDrawingCache();
Utils.saveBitmapOnSdcard(bmap);
toppest.setDrawingCacheEnabled(false);
无论如何,此屏幕截图不包含操作栏。
如何使用 actionBar 截屏?
有关信息:我将 Sherlock 操作栏实现与 windowActionBarOverlay 选项设置为“true”。
最佳答案
我找到了解决方案。需要使用 ctx.getWindow().getDecorView() View 获取全屏位图缓存。
此外,还有一个小细节:屏幕截图包含状态栏的空白区域。我们在 Window.ID_ANDROID_CONTENT 上边距的帮助下跳过状态栏高度。最后,这给出了与我们之前在手机上看到的大小相同的 Activity 的完整屏幕截图:
View view = ctx.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap bmap = view.getDrawingCache();
Log.i(TAG,"bmap:" + b);
int contentViewTop = ctx.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); /* skip status bar in screenshot */
Storage.shareBitmapInfo = Bitmap.createBitmap(bmap, 0, contentViewTop, bmap.getWidth(), bmap.getHeight() - contentViewTop, null, true);
view.setDrawingCacheEnabled(false);
关于带有操作栏的 Activity 的 Android 屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194118/