在Android中为应用程序设置NoTitleBar样式时为getDrawingCache

时间:2011-08-02 07:19:22

标签: android screenshot

在我的清单中,我指定了(对于整个应用程序)样式:

  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模式下获得“真实”截图?

1 个答案:

答案 0 :(得分:0)

如果可以

尝试打开/关闭标题栏
/** set title bar to ON  */
activityView.setDrawingCacheEnabled(true);
Bitmap currentScreen = Bitmap.createBitmap(activityView.getDrawingCache());
activityView.setDrawingCacheEnabled(false);
/** set title bar to OFF  */

编辑:

我还没有尝试过,我不确定是否能够正常工作,但您是否尝试使用findViewById引用截图到主要(xml中的第一个)布局?你还有标题栏的问题吗?