活动与动作条的Andr​​oid截图 [英] Android screenshot of activity with actionbar

查看:161
本文介绍了活动与动作条的Andr​​oid截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于活动与动作条的Andr​​oid截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆