Reputation: 76989
I used to snap bitmaps of activities by taking their content
view and drawing it:
View view = activity.findViewById(android.R.id.content)
Bitmap bitmap = Bitmap.createBitmap(
view.getWidth(), view.getHeight(), Config.ARGB_8888
);
view.draw(new Canvas(bitmap));
Now I'm using an ActionBar, and it's not nested under the content
view, so it's left out. How can I obtain the real root view? Or snap a picture with the action bar in some other way, if that's not possible?
Upvotes: 2
Views: 2152
Reputation: 993
To get a Bitmap for the entire window including ActionBar you can use the DecorView.
First you need to enable drawing cache
getWindow().getDecorView().setDrawingCacheEnabled(true);
get the bitmap
Bitmap bmp = getWindow().getDecorView().getDrawingCache();
Use the bitmap elsewhere, I try this with a ImageView and works great.
disable drawing cache
getWindow().getDecorView().setDrawingCacheEnabled(false);
Upvotes: 5