Convert a translucent themed Activity android.R.attr#windowIsTranslucent back from opaque to translucent following a call to #convertActivityFromTranslucent(android.app.Activity) . - Android Activity

Android examples for Activity:Activity Feature

Description

Convert a translucent themed Activity android.R.attr#windowIsTranslucent back from opaque to translucent following a call to #convertActivityFromTranslucent(android.app.Activity) .

Demo Code


//package com.java2s;
import android.app.Activity;
import java.lang.reflect.Method;

public class Main {

    public static void convertActivityToTranslucent(Activity activity) {
        try {//from ww  w .j ava  2 s  . c om
            Class<?>[] classes = Activity.class.getDeclaredClasses();
            Class<?> translucentConversionListenerClazz = null;
            for (Class clazz : classes) {
                if (clazz.getSimpleName().contains(
                        "TranslucentConversionListener")) {
                    translucentConversionListenerClazz = clazz;
                }
            }
            Method method = Activity.class.getDeclaredMethod(
                    "convertToTranslucent",
                    translucentConversionListenerClazz);
            method.setAccessible(true);
            method.invoke(activity, new Object[] { null });
        } catch (Throwable t) {
        }
    }
}

Related Tutorials