convert Activity To Translucent - Android Activity

Android examples for Activity:Activity Background

Description

convert Activity To Translucent

Demo Code


//package com.java2s;
import android.app.Activity;
import android.app.ActivityOptions;

import android.os.Build;

import java.lang.reflect.Method;

public class Main {
    public static void convertActivityToTranslucent(Activity activity) {
        try {//from  w  ww.  j a va2  s  .com
            Class<?>[] classes = Activity.class.getDeclaredClasses();
            Class<?> translucentConversionListenerClazz = null;
            for (Class clazz : classes) {
                if (clazz.getSimpleName().contains(
                        "TranslucentConversionListener")) {
                    translucentConversionListenerClazz = clazz;
                }
            }
            if (Build.VERSION.SDK_INT < 21) {
                Method method = Activity.class.getDeclaredMethod(
                        "convertToTranslucent",
                        translucentConversionListenerClazz);
                method.setAccessible(true);
                method.invoke(activity, new Object[] { null });
            } else {
                Method method = Activity.class.getDeclaredMethod(
                        "convertToTranslucent",
                        translucentConversionListenerClazz,
                        ActivityOptions.class);
                method.setAccessible(true);
                method.invoke(activity, new Object[] { null, null });
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

Related Tutorials