开发者

getDrawingCache while NoTitleBar style set for the application in Android

开发者 https://www.devze.com 2023-03-25 03:05 出处:网络
In my manifest I specified (for an entire applic开发者_StackOverflowation) style: android:theme=\"@android:style/Theme.NoTitleBar\"

In my manifest I specified (for an entire applic开发者_StackOverflowation) 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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号