gpt4 book ai didi

带有操作栏的 Activity 的 Android 屏幕截图

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:45 24 4
gpt4 key购买 nike

我使用这些行来截取我的 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);

无论如何,此屏幕截图不包含操作栏。

如何使用 actionBar 截屏?

有关信息:我将 Sherlock 操作栏实现与 windowActionBarOverlay 选项设置为“true”。

最佳答案

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

此外,还有一个小细节:屏幕截图包含状态栏的空白区域。我们在 Window.ID_ANDROID_CONTENT 上边距的帮助下跳过状态栏高度。最后,这给出了与我们之前在手机上看到的大小相同的 Activity 的完整屏幕截图:

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

关于带有操作栏的 Activity 的 Android 屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com