Java Code Examples for android.view.View#SYSTEM_UI_FLAG_IMMERSIVE
The following examples show how to use
android.view.View#SYSTEM_UI_FLAG_IMMERSIVE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VOIPVoiceActivity.java From voip_android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void run() { int flags; int curApiVersion = android.os.Build.VERSION.SDK_INT; // This work only for android 4.4+ if (curApiVersion >= Build.VERSION_CODES.KITKAT) { // This work only for android 4.4+ // hide navigation bar permanently in android activity // touch the screen, the navigation bar will not show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_FULLSCREEN; } else { // touch the screen, the navigation bar will show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // must be executed in main thread :) getWindow().getDecorView().setSystemUiVisibility(flags); }
Example 2
Source File: VOIPVideoActivity.java From voip_android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void run() { int flags; int curApiVersion = android.os.Build.VERSION.SDK_INT; // This work only for android 4.4+ if (curApiVersion >= Build.VERSION_CODES.KITKAT) { // This work only for android 4.4+ // hide navigation bar permanently in android activity // touch the screen, the navigation bar will not show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_FULLSCREEN; } else { // touch the screen, the navigation bar will show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // must be executed in main thread :) getWindow().getDecorView().setSystemUiVisibility(flags); }
Example 3
Source File: MainActivity.java From Droid2JoyStick with Apache License 2.0 | 6 votes |
@Override public void enterFullscreen() { isFullscreen = true; int uiOption = 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 | View.SYSTEM_UI_FLAG_FULLSCREEN; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { uiOption |= View.SYSTEM_UI_FLAG_IMMERSIVE; } getWindow().getDecorView().setSystemUiVisibility(uiOption); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (getSupportActionBar() != null) { getSupportActionBar().hide(); } ndMenu.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); }
Example 4
Source File: BaseActivity.java From Android-Application-ZJB with Apache License 2.0 | 6 votes |
/** * Hide navigation bar. */ public final void hideNavigationBar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_IMMERSIVE; View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(uiOptions); } else { WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(lp); } }
Example 5
Source File: ExoVideoControlsMobile.java From v9porn with MIT License | 6 votes |
/** * Determines the appropriate fullscreen flags based on the * systems API version. * * @return The appropriate decor view flags to enter fullscreen mode when supported */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private int getFullscreenUiFlags() { int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { flags |= View.SYSTEM_UI_FLAG_IMMERSIVE; } return flags; }
Example 6
Source File: GalleryPreviewDetail.java From moviedb-android with Apache License 2.0 | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (activity.getSupportActionBar() != null && activity.getSupportActionBar().isShowing()) activity.getSupportActionBar().hide(); if (Build.VERSION.SDK_INT >= 19) { mUIFlag ^= View.SYSTEM_UI_FLAG_IMMERSIVE; } if (this.isVisible()) { // Check orientation and lock to portrait if we are on phone if (getResources().getBoolean(R.bool.portrait_only)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } imageLoader.displayImage(currImg, mImageView, options, imageLoadingListener); }
Example 7
Source File: RecordVideoActivity.java From TikTok with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隐藏状态栏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams params = getWindow().getAttributes(); params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE; getWindow().setAttributes(params); setContentView(R.layout.activity_tidal_pat_record_video); mMusicBean = (MusicBean) getIntent().getSerializableExtra("MusicBean"); mPresenter = new RecordVideoPresenter(this, mMusicBean); initView(); boolean isAudioPermission = CheckPermissionUtil.isHasAudioPermission(this); if (!isAudioPermission) { mCircleRecordView.setCanTouch(isAudioPermission); ToastTool.showShort(AppUtil.getApplicationContext(), R.string.tidal_pat_record_check_audio_permission); } }
Example 8
Source File: ImagePagerFragment.java From Hentoid with Apache License 2.0 | 6 votes |
/** * Show / hide bottom and top Android system bars * * @param visible True if bars have to be shown; false instead */ private void setSystemBarsVisible(boolean visible) { int uiOptions; if (visible) { uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; } else { uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE // Set the content to appear under the system bars so that the // content doesn't resize when the system bars hide and show. | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // Hide the nav bar and status bar | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; } // Defensive programming here because crash reports show that getView() sometimes is null // (just don't ask me why...) View v = getView(); if (v != null) v.setSystemUiVisibility(uiOptions); }
Example 9
Source File: SystemUiHelperImplKK.java From EhViewer with Apache License 2.0 | 6 votes |
@Override protected int createHideFlags() { int flag = super.createHideFlags(); if (mLevel == SystemUiHelper.LEVEL_IMMERSIVE) { // If the client requested immersive mode, and we're on Android 4.4 // or later, add relevant flags. Applying HIDE_NAVIGATION without // IMMERSIVE prevents the activity from accepting all touch events, // so we only do this on Android 4.4 and later (where IMMERSIVE is // present). flag |= ((mFlags & SystemUiHelper.FLAG_IMMERSIVE_STICKY) != 0) ? View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY : View.SYSTEM_UI_FLAG_IMMERSIVE; } return flag; }
Example 10
Source File: KeyguardActivity.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
public void setSystemUiVisibilityFake() { int visibility = SYSTEM_UI_BASIC_FLAGS | View.SYSTEM_UI_FLAG_IMMERSIVE; if (getConfig().isFullScreen()) { visibility |= View.SYSTEM_UI_FLAG_FULLSCREEN; } getWindow().getDecorView().setSystemUiVisibility(visibility); }
Example 11
Source File: DemoActivity.java From GestureViews with Apache License 2.0 | 5 votes |
/** * Shows or hides system UI (status bar and navigation bar). */ private void showSystemUi(boolean show) { int flags = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE; } getWindow().getDecorView().setSystemUiVisibility(show ? 0 : flags); }
Example 12
Source File: MainActivity.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
/** * 隐藏虚拟按键,并且全屏 */ protected void hideBottomUIMenu() { //隐藏虚拟按键,并且全屏 int flags; int curApiVersion = android.os.Build.VERSION.SDK_INT; // This work only for android 4.4+ if (curApiVersion >= Build.VERSION_CODES.KITKAT) { // This work only for android 4.4+ // hide navigation bar permanently in android activity // touch the screen, the navigation bar will not show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_FULLSCREEN; } else { // touch the screen, the navigation bar will show flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // must be executed in main thread :) getWindow().getDecorView().setSystemUiVisibility(flags); // if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api // View v = this.getWindow().getDecorView(); // v.setSystemUiVisibility(View.GONE); // } else if (Build.VERSION.SDK_INT >= 19) { // Window window = getWindow(); // WindowManager.LayoutParams params = window.getAttributes(); // params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; // window.setAttributes(params); // //// //for new api versions. //// View decorView = getWindow().getDecorView(); //// int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN; //// decorView.setSystemUiVisibility(uiOptions); // } }
Example 13
Source File: GalleryPreviewSlide.java From moviedb-android with Apache License 2.0 | 5 votes |
/** * @param savedInstanceState if the fragment is being re-created from a previous saved state, this is the state. */ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (activity.getSupportActionBar() != null) activity.getSupportActionBar().hide(); if (Build.VERSION.SDK_INT >= 19) { mUIFlag ^= View.SYSTEM_UI_FLAG_IMMERSIVE; } activity.getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(activity, R.color.black)); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) activity.getWindow().getDecorView().setSystemUiVisibility(mUIFlag); else activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); }
Example 14
Source File: PhotoImageActivity.java From v9porn with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private int getFullscreenUiFlags() { int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { flags |= View.SYSTEM_UI_FLAG_IMMERSIVE; } return flags; }
Example 15
Source File: PictureViewerActivity.java From v9porn with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private int getFullscreenUiFlags() { int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { flags |= View.SYSTEM_UI_FLAG_IMMERSIVE; } return flags; }
Example 16
Source File: ViewUtil.java From BaseProject with Apache License 2.0 | 5 votes |
public static void hideNavigation(Window curWindow) { if (curWindow != null && Build.VERSION.SDK_INT >= 19) { //隐藏Navigation bar WindowManager.LayoutParams layoutParams = curWindow.getAttributes(); layoutParams.systemUiVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ; // layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; curWindow.setAttributes(layoutParams); // View decorView = curWindow.getDecorView(); // if (decorView != null) { // int oldUiFlags = decorView.getSystemUiVisibility(); // int uiFlags = // oldUiFlags | // View.SYSTEM_UI_FLAG_LAYOUT_STABLE //// | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS // | View.SYSTEM_UI_FLAG_IMMERSIVE // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //// | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //// | View.SYSTEM_UI_FLAG_FULLSCREEN // | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; // decorView.setSystemUiVisibility(uiFlags); // } } }
Example 17
Source File: ViewUtil.java From BaseProject with Apache License 2.0 | 4 votes |
/** * 代码的方式来设置沉浸式界面 * @param curActivity 当前Activity * @param needFullScreen 是否需要全屏:一般为false * @param translucentNavBar 是否需要透明导航栏:一般为true * @param hideNavigation 是否要隐藏导航栏: 一般为true * @param drawStatusBarBg 是否需要在Android 5.0及以上 接管状态栏背景绘制,用于指定 状态栏背景颜色 * @param statusBarColor 想要的状态栏颜色 * @param isLightStatusBar 是否需要在Android 6.0及以上 启用状态栏的灰色文字和图标 */ public static void immersiveScreen(Activity curActivity,boolean needFullScreen, boolean translucentNavBar,boolean hideNavigation, boolean drawStatusBarBg, int statusBarColor,boolean isLightStatusBar) { if (curActivity != null) { Window window = curActivity.getWindow(); if (window != null) { WindowManager.LayoutParams windowParams = window.getAttributes(); if (windowParams != null) { //已经存在的 可见性参数 int mayExistVisibility = windowParams.systemUiVisibility; // int mayExistFlags = windowParams.flags; int curSdkInt = Build.VERSION.SDK_INT; if (needFullScreen) { // mayExistFlags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } if (curSdkInt >= 19) {//Android 4.4后才有沉浸式 if (translucentNavBar) { // mayExistFlags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } //默认的实现沉浸式flag window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (curSdkInt >= 21) { if (drawStatusBarBg) {//如果需要 代替绘制状态栏的背景,则需要清除 FLAG_TRANSLUCENT_STATUS window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } if (statusBarColor != -1) { window.setStatusBarColor(statusBarColor); } if (curSdkInt >= 23) {//Android 6.0以上 实现状态栏字色和图标浅黑色 if (isLightStatusBar) { mayExistVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; } } } if (hideNavigation) {//隐藏导航栏 mayExistVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ; windowParams.systemUiVisibility = mayExistVisibility; window.setAttributes(windowParams); } }//curSdkInt >= 19 end } } } }
Example 18
Source File: VideoCropActivity.java From TikTok with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隐藏状态栏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams params = getWindow().getAttributes(); params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_IMMERSIVE; getWindow().setAttributes(params); setContentView(R.layout.activity_tidal_pat_video_crop); mCurrentVideoPath = getIntent().getStringExtra("mCurrentVideoPath"); mPlayView = (SpecialEffectsPlayView) findViewById(R.id.tidal_pat_crop_video_pv); mPlayView.setLooping(true); mPlayView.setNeedCallBackFinish(true); SpecialEffectsPlayManager.startPlay(mPlayView); mVideoCropViewBar = findViewById(R.id.tidal_pat_video_crop_crop_view); mSpeedLevelControllerView = findViewById(R.id.tidal_pat_video_crop_speed_controller_view); mSaveImg = findViewById(R.id.tidal_pat_crop_video_save_img); mSelectedTxt = findViewById(R.id.tidal_pat_video_crop_selected_time_txt); mVideoCropViewBar.setVideoCropViewBarListener(mVideoCropViewBarListener); mVideoCropViewBar.setVideoPath(mCurrentVideoPath); mPlayView.setVideoPath(mCurrentVideoPath); mSpeedLevelControllerView.setOnSpeedLevelChangeListener(mSpeedLevelChangeListener); mSaveImg.setOnClickListener(this); findViewById(R.id.tidal_pat_crop_video_back_img).setOnClickListener(this); mPlayView.setSpecialEffectsPlayViewListener(mPlayViewListener); mLoadingView = findViewById(R.id.personal_show_record_video_loading_layout); mLoadingView.setOnClickListener(this); mLoadingTxt = (TextView) findViewById(R.id.tidal_pat_record_video_loading_txt); initRecordTimeSelectorView(); }
Example 19
Source File: AdvancedImmersiveModeFragment.java From android-AdvancedImmersiveMode with Apache License 2.0 | 4 votes |
/** * Detects and toggles immersive mode (also known as "hidey bar" mode). */ public void toggleUiFlags() { // BEGIN_INCLUDE (get_current_ui_flags) // The "Decor View" is the parent view of the Activity. It's also conveniently the easiest // one to find from within a fragment, since there's a handy helper method to pull it, and // we don't have to bother with picking a view somewhere deeper in the hierarchy and calling // "findViewById" on it. View decorView = getActivity().getWindow().getDecorView(); int uiOptions = decorView.getSystemUiVisibility(); int newUiOptions = uiOptions; // END_INCLUDE (get_current_ui_flags) // BEGIN_INCLUDE (toggle_lowprofile_mode) // Low profile mode doesn't resize the screen at all, but it covers the nav & status bar // icons with black so they're less distracting. Unlike "full screen" and "hide nav bar," // this mode doesn't interact with immersive mode at all, but it's instructive when running // this sample to observe the differences in behavior. if (mLowProfileCheckBox.isChecked()) { newUiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE; } else { newUiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; } // END_INCLUDE (toggle_lowprofile_mode) // BEGIN_INCLUDE (toggle_fullscreen_mode) // When enabled, this flag hides non-critical UI, such as the status bar, // which usually shows notification icons, battery life, etc // on phone-sized devices. The bar reappears when the user swipes it down. When immersive // mode is also enabled, the app-drawable area expands, and when the status bar is swiped // down, it appears semi-transparently and slides in over the app, instead of pushing it // down. if (mHideStatusBarCheckBox.isChecked()) { newUiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN; } else { newUiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; } // END_INCLUDE (toggle_fullscreen_mode) // BEGIN_INCLUDE (toggle_hidenav_mode) // When enabled, this flag hides the black nav bar along the bottom, // where the home/back buttons are. The nav bar normally instantly reappears // when the user touches the screen. When immersive mode is also enabled, the nav bar // stays hidden until the user swipes it back. if (mHideNavCheckbox.isChecked()) { newUiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } else { newUiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // END_INCLUDE (toggle_hidenav_mode) // BEGIN_INCLUDE (toggle_immersive_mode) // Immersive mode doesn't do anything without at least one of the previous flags // enabled. When enabled, it allows the user to swipe the status and/or nav bars // off-screen. When the user swipes the bars back onto the screen, the flags are cleared // and immersive mode is automatically disabled. if (mImmersiveModeCheckBox.isChecked()) { newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE; } else { newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE; } // END_INCLUDE (toggle_immersive_mode) // BEGIN_INCLUDE (toggle_immersive_mode_sticky) // There's actually two forms of immersive mode, normal and "sticky". Sticky immersive mode // is different in 2 key ways: // // * Uses semi-transparent bars for the nav and status bars // * This UI flag will *not* be cleared when the user interacts with the UI. // When the user swipes, the bars will temporarily appear for a few seconds and then // disappear again. if (mImmersiveModeStickyCheckBox.isChecked()) { newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } else { newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } // END_INCLUDE (toggle_immersive_mode_sticky) // BEGIN_INCLUDE (set_ui_flags) //Set the new UI flags. decorView.setSystemUiVisibility(newUiOptions); // END_INCLUDE (set_ui_flags) dumpFlagStateToLog(uiOptions); }
Example 20
Source File: ViewUtils.java From BlueBoard with Apache License 2.0 | 4 votes |
/** * Detects and toggles immersive mode (also known as "hidey bar" mode). */ public static void toggleHideyBar(View decorView) { // The UI options currently enabled are represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = decorView.getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { // Log.i(TAG, "Turning immersive mode mode off. "); } else { // Log.i(TAG, "Turning immersive mode mode on."); } // Navigation bar hiding: Backwards compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bar hiding: Backwards compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backward compatible to KitKat. // Note that this flag doesn't do anything by itself, it only augments the behavior // of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample // all three flags are being toggled together. // Note that there are two immersive mode UI flags, one of which is referred to as "sticky". // Sticky immersive mode differs in that it makes the navigation and status bars // semi-transparent, and the UI flag does not get cleared when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } if (Build.VERSION.SDK_INT >= 19) { newUiOptions ^= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE; } decorView.setSystemUiVisibility(newUiOptions); }