I am doing a simple lockscreen using the addview in windowmanager, although i successfully added the lockscreen view but before the view is added, a white annoying page being added before the view is displayed. i tried to set the view background to other color but it didn't affected anything so i think it might be something related to the window view, after changing background color in activity, delayed addview, it still appeared.
ps: when remove view when i called before finish(), then white view appeared, but when remove view in ondestroyed, it will delayed a bit but the white view will not appeared.
How can i remove/hide this white view when addView/removeView?
public static synchronized LockUtil getInstance(Activity act) {
if (mLockLayer == null) {
mLockLayer = new LockUtil(act);
}
return mLockLayer;
}
private LockUtil(Activity act) {
mActivty = act;
init();
}
private void init() {
isLocked = false;
if (null == mWindowManager) {
mWindowManager = ((WindowManager) mActivty.getSystemService(Context.WINDOW_SERVICE));
}
mLockViewLayoutParams = new WindowManager.LayoutParams();
mLockViewLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
mLockViewLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
mLockViewLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
mLockViewLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mLockViewLayoutParams.windowAnimations = android.R.style.Animation_Translucent;
}
public synchronized void lock() {
if (mLockView != null && !isLocked) {
mWindowManager.addView(mLockView, mLockViewLayoutParams);
isLocked = true;
}
}
public synchronized void unlock() {
if (mWindowManager != null && isLocked) {
try{
mWindowManager.removeView(mLockView);
isLocked = false;
}catch(IllegalArgumentException e){
Logger.e("LockUtil unlock failed:"+e.getMessage());
}
}
mActivty = null;
}
After make some of the research, the white background is the background color for the activity (window) so in order to remove it, we just need to set the color to transparent in the theme.
<style name="Theme.Transparent" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>