活动与动作条的Andr​​oid截图截图、动作、Andr、oid

由网友(花谢烟雨迟)分享简介:我用这些线把我的活动截图:I use these lines to take screenshot of my activity:View toppest = ((ViewGroup) ctx.getWindow().getDecorView().findViewById(android.R.id.content)...

我用这些线把我的活动截图:

I use these lines to take screenshot of my 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);

不管怎样,这个截图不包含动作条。

Anyway, this screenshot not contain actionbar.

我怎样才能使屏幕截图与动作条?

How I can make screenshot with actionBar ?

有关的信息:我用福尔摩斯动作条的实施与windowActionBarOverlay选项为true

For information: I use Sherlock actionbar implementation with windowActionBarOverlay option to "true".

推荐答案

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

I found solution. Need to use ctx.getWindow().getDecorView() View to get full screen bitmap cache.

此外,还有小细节:截图包含了状态栏的空白区域。我们跳过状态栏的高度与Window.ID_ANDROID_CONTENT上边距帮助。最后,这给具有相同大小的活动完全screenhot正如我们之前看到它在我们的电话:

Also, there is small detail: screenshot contains empty space for status bar. We skip status bar height with help of Window.ID_ANDROID_CONTENT top margin. Finally, this give full screenhot of activity with same size as we saw it before on our telephone :

  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);
阅读全文

相关推荐

最新文章