带动作栏的活动的Android屏幕截图

Ser*_*nko 5 android screenshot android-actionbar

我使用这些行来截取我的活动:

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);
Run Code Online (Sandbox Code Playgroud)

无论如何,这个截图不包含actionbar.

如何使用actionBar制作屏幕截图?

有关信息:我使用Sherlock actionbar实现windowActionBarOverlay选项为"true".

Ser*_*nko 7

我找到了解决方案 需要使用ctx.getWindow().getDecorView()查看以获得全屏位图缓存.

此外,还有一个小细节:屏幕截图包含状态栏的空白区域.我们借助Window.ID_ANDROID_CONTENT上边距跳过状态栏高度.最后,这会给我们以前在电话上看到的相同尺寸的活动全屏:

  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);
Run Code Online (Sandbox Code Playgroud)