我用这些线把我的活动的截图:
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);
无论如何,这个截图不包含动作条。
我怎样才能使屏幕截图与动作条?
有关信息:我用福尔摩斯动作条的实施与windowActionBarOverlay选项为“true”。
I found solution. Need to use ctx.getWindow().getDecorView() View to get full screen bitmap cache.
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);
该解决方案可以在这里找到:
状态栏的高度?
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);