<pre><code>/** * @author wilber * @target 4.1 * @requirements:4.1平板隱藏系統欄 * @theme android4.1 平板隱藏System Bar * @remark 轉載請註明出處http://my.oschina.net/wilber */</code></pre>java
/** * 設置系統欄可見性 */ public static void setSystemBarVisible(final Activity context,boolean visible) { int flag = context.getWindow().getDecorView().getSystemUiVisibility(); // 獲取當前SystemUI顯示狀態 // int fullScreen = View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN; int fullScreen = 0x8; // 4.1 View.java的源碼裏面隱藏的常量SYSTEM_UI_FLAG_SHOW_FULLSCREEN,其實Eclipse裏面也能夠調用系統隱藏接口,從新提取下android.jar,這裏就不述了。 if(visible) { // 顯示系統欄 if((flag & fullScreen) != 0) { // flag標誌位中已經擁有全屏標誌SYSTEM_UI_FLAG_SHOW_FULLSCREEN context.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); // 顯示系統欄 } } else { // 隱藏系統欄 if((flag & fullScreen) == 0) { // flag標誌位中不存在全屏標誌SYSTEM_UI_FLAG_SHOW_FULLSCREEN context.getWindow().getDecorView().setSystemUiVisibility(flag | fullScreen); // 把全屏標誌位加進去 } } }
/** * 判斷狀態欄是否顯示 */ public static boolean isSystemBarVisible(final Activity context) { int flag = context.getWindow().getDecorView().getSystemUiVisibility(); // return (flag & View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN) != 0; return (flag & 0x8) == 0; }