0
我想動態改變Activity的背景爲透明。在Android API-21下面,Activity的convertToTranslucent方法無效嗎?
以上API-21,convertToTranslucent
方法是有用的。
但它在API-21下無效。
這是我的調用代碼:活動
public void convertToTranslucent(TranslucentConversionListener callback) {
try {
mTranslucentCallback = callback;
mChangeCanvasToTranslucent =
ActivityManagerNative.getDefault().convertToTranslucent(mToken);
} catch (RemoteException e) {
// pass
}
}
的
public static void convertActivityToTranslucentBeforeL(Activity activity) {
try {
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) {
t.printStackTrace();
}
}
convertToTranslucent方法我發現mChangeCanvasToTranslucent的號召後的值是假的