2017-06-06 86 views
0

當屏幕方向爲PORTRAIT時,我需要使狀態爲TRANSLUCENT。
同時,當屏幕方向爲LANDSCAPE時,我需要將其設置爲正常。如何切換狀態TRANSLUCENT?

現在我overwritte的onConfigurationChanged,並調用此方法切換狀態模式:

@TargetApi(19) 
public static void setTranslucentStatus(Activity activity, boolean on) { 
    Window win = activity.getWindow(); 
    if (on) { 
     win.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
    } else { 
     win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
     win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
      View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 
    } 
} 

但有一個醜陋的白色的東西在屏幕的頂部: White thing

爲什麼呢?

回答

0

您對屏幕的方向

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ 
win.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
} else { 
    win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
    win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
     View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 
} 
+0

首先檢查我不喜歡這些在onConfiguration回調,但偷的工作並不好 – RainFool