标签:
1.隐藏标题栏(titlebar)
(1)在代码中隐藏标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
(2)在Manifest中Application或Activity中配置主题样式
android:theme="@android:style/Theme.NoTitleBar"
2.隐藏状态栏(statusbar)
(1)在Manifest中Activity中配置主题样式
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
(2)在代码中隐藏状态栏
/** * 隐藏状态栏 */ private void hideStatusBar() { //定义全屏参数 int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN; //获得当前窗体对象 Window window = MainActivity.this.getWindow(); //设置当前窗体为全屏显示 window.setFlags(flag, flag); }
3.隐藏导航栏(NavigationBar)
/** * 隐藏导航栏,可返回 */ private void hideNavigationBarCanBack() { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); }
4.同时隐藏状态栏和导航栏
/** * 隐藏导航栏 */ public void hideNavigationBarAndStatusBar() { int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN; // hide status bar if (android.os.Build.VERSION.SDK_INT >= 19) { //SYSTEM_UI_FLAG_IMMERSIVE_STICKY: hide navigation bars - compatibility: building API level is lower thatn 19, use magic number directly for higher API target level uiFlags |= 0x00001000; } else { uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE; } getWindow().getDecorView().setSystemUiVisibility(uiFlags); }
5.动态全屏与退出
/** * 动态设置全屏 */ private void dynamicFullScreen(){ WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } /** * 动态退出全屏 */ private void dynamicExitFullScreen(){ WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); }
标签:
原文地址:http://www.cnblogs.com/pillowzhou/p/4897334.html