<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; }