Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有actionbar的Android活动截图_Android_Android Actionbar_Screenshot - Fatal编程技术网

带有actionbar的Android活动截图

带有actionbar的Android活动截图,android,android-actionbar,screenshot,Android,Android Actionbar,Screenshot,我用以下几行文字拍摄我的活动截图: View toppest = ((ViewGroup) ctx.getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0); toppest.setDrawingCacheEnabled(true); Bitmap bmap = toppest.getDrawingCache(); Utils.saveBitmapOnSdcard(bmap); toppest.set

我用以下几行文字拍摄我的活动截图:

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

如何使用actionBar制作屏幕截图


仅供参考:我使用Sherlock actionbar实现,将windowActionBarOverlay选项设置为“true”。

我找到了解决方案。需要使用ctx.getWindow().getDecorView()视图来获取全屏位图缓存

此外,还有一些小细节:屏幕截图包含状态栏的空白。借助Window.ID\u ANDROID\u内容顶部边距,我们跳过状态栏的高度。最后,这将提供与我们之前在电话中看到的大小相同的活动的完整屏幕截图:

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

可以在以下位置找到解决方案:


你只想拍屏幕快照,这个解决方案对我不起作用。getTop()调用返回除操作栏之外的内容的开头。其工作原理类似于charm!谢谢:)上下文没有getWindow方法(活动有)。
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);