设置Activity为透明

设置Activity为透明

  private void translucentActivity(Activity activity) {

    try {
        activity.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        activity.getWindow().getDecorView().setBackground(null);
        Method activityOptions = Activity.class.getDeclaredMethod("getActivityOptions");
        activityOptions.setAccessible(true);
        Object options = activityOptions.invoke(activity);

        Class[] classes = Activity.class.getDeclaredClasses();
        Class aClass = null;
        for (Class clazz : classes) {
            if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
                aClass = clazz;
            }
        }
        Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
                aClass, ActivityOptions.class);
        method.setAccessible(true);
        method.invoke(activity, null, options);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

你可能感兴趣的:(技术文档)