5

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

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”。

4

2 回答 2

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);
于 2012-11-07T15:03:33.220 回答
3

可以在这里找到解决方案:

状态栏的高度?

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

   Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight);
于 2013-04-23T00:32:24.237 回答