在我的 list 中,我指定(针对整个应用程序)样式:
android:theme="@android:style/Theme.NoTitleBar"
然后在我的应用程序中,我想使用绘图缓存创建应用程序的屏幕截图:
View activityView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
activityView.setDrawingCacheEnabled(true);
Bitmap currentScreen = Bitmap.createBitmap(activityView.getDrawingCache());
activityView.setDrawingCacheEnabled(false);
问题是屏幕截图顶部有一个间隙(标题栏的大小)。如果标题栏打开,或者应用程序处于全屏模式,我会得到正确的屏幕截图。我尝试使用 buildDrawingCache(true),但没有任何区别。知道如何在 noTitleBar 模式下获得“真实”屏幕截图吗?
最佳答案
如果可以,请尝试打开/关闭标题栏
/** set title bar to ON */
activityView.setDrawingCacheEnabled(true);
Bitmap currentScreen = Bitmap.createBitmap(activityView.getDrawingCache());
activityView.setDrawingCacheEnabled(false);
/** set title bar to OFF */
编辑:
我没有尝试过,我不确定是否会起作用,但是您是否尝试过通过使用 findViewById 引用它来为您的主要(第一个在 xml 中)布局制作屏幕截图?标题栏还有问题吗?
关于android - getDrawingCache while NoTitleBar style set for the application in Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6908509/