Example usage for android.view ViewGroup getDrawingCache

List of usage examples for android.view ViewGroup getDrawingCache

Introduction

In this page you can find the example usage for android.view ViewGroup getDrawingCache.

Prototype

@Deprecated
public Bitmap getDrawingCache(boolean autoScale) 

Source Link

Document

Returns the bitmap in which this view drawing is cached.

Usage

From source file:Main.java

/**
 * Take screenshot of the activity including the action bar
 * /*w  ww .  j  a va 2s  .com*/
 * @param activity
 * @return The screenshot of the activity including the action bar
 */
public static Bitmap takeScreenshot(Activity activity) {
    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setDrawingCacheEnabled(true);
    decorChild.buildDrawingCache();
    Bitmap drawingCache = decorChild.getDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(drawingCache);
    decorChild.setDrawingCacheEnabled(false);
    return bitmap;
}