7

In my manifest I specified (for an entire application) style:

  android:theme="@android:style/Theme.NoTitleBar"

Then in my app I want to create a screenshot of the app using drawing cache:

  View activityView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
  activityView.setDrawingCacheEnabled(true);
  Bitmap currentScreen = Bitmap.createBitmap(activityView.getDrawingCache());
  activityView.setDrawingCacheEnabled(false);

Problem is that on the screenshot there is a gap on top (size of the title bar). I get the right screenshot if title bar is on, or if the app is in the fullscreen mode. I tried to use buildDrawingCache(true), but it made no difference. Any idea how can I can get a "real" screenshot in noTitleBar mode?

zilinx
  • 1,052
  • 8
  • 18

1 Answers1

0

Try to on/off your title bar if you can

/** set title bar to ON  */
activityView.setDrawingCacheEnabled(true);
Bitmap currentScreen = Bitmap.createBitmap(activityView.getDrawingCache());
activityView.setDrawingCacheEnabled(false);
/** set title bar to OFF  */

EDIT:

I haven't tried and I'm not sure if will going to work, but have you tried to make a screenshot to your main (first in xml) layout by referencing it with findViewById? Do you still have problems with the title bar?

Radu Dan
  • 453
  • 4
  • 22
  • It's a good idea for a workaround, but switching title bar on/off is troublesome (details in [this SO post](http://stackoverflow.com/questions/991764/hiding-title-in-a-fullscreen-mode)). With fragments that may not even be possible. Nonetheless, thanks for your input! – zilinx Sep 24 '11 at 12:22