Example usage for android.view ViewGroup buildDrawingCache

List of usage examples for android.view ViewGroup buildDrawingCache

Introduction

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

Prototype

@Deprecated
public void buildDrawingCache() 

Source Link

Document

Calling this method is equivalent to calling buildDrawingCache(false).

Usage

From source file:Main.java

/**
 * Take screenshot of the activity including the action bar
 * //www.j  a  va 2 s.c  o m
 * @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;
}