Immersivemode immersion mode of Androidのui experience

Source: Internet
Author: User

To turn on immersion mode:

/**
* Detects and Toggles immersive mode (also known as "Hidey Bar" mode). */
public void Togglehideybar () {//Begin_include (Get_current_ui_flags)
The UI options currently enabled is represented by a bitfield.
Getsystemuivisibility () gives us that bitfield.
int uioptions = Getactivity (). GetWindow (). Getdecorview (). getsystemuivisibility ();        int newuioptions = uioptions; End_include (Get_current_ui_flags)
Begin_include (Toggle_ui_flags)
Boolean isimmersivemodeenabled =
((Uioptions |        View.system_ui_flag_immersive_sticky) = = uioptions); if (isimmersivemodeenabled) {
LOG.I (TAG, "Turning immersive mode off.");
} else {
LOG.I (TAG, "Turning immersive 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 does anything by itself, it is only augments the behavior
of Hide_navigation and Flag_fullscreen. For the purposes of this sample
All three flags is being toggled together.
Note that there was immersive mode UI flags, one of the 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 if the user interacts with
The screen.
if (Build.VERSION.SDK_INT >= 18) {
Newuioptions ^= View.system_ui_flag_immersive_sticky;
}

Getactivity (). GetWindow (). Getdecorview (). setsystemuivisibility (newuioptions); End_include (Set_ui_flags)
}
And this change in status can show this listener:
Final View Decorview = getactivity (). GetWindow (). Getdecorview ();
Decorview.setonsystemuivisibilitychangelistener (New View.onsystemuivisibilitychangelistener () { @Override
public void Onsystemuivisibilitychange (int i) {int height = decorview.getheight ();
LOG.I (TAG, "current height:" + height);
}
});
There are 5 different flag roles in total.
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 screens 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 @ all, but it's instructive when running
This is a sample to observe the differences in behavior.
if (mlowprofilecheckbox.ischecked ()) {
Newuioptions |= view.system_ui_flag_low_profile;//Low profile mode: Notification bar and virtual key dimming
} 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 if the status bar is swiped
Down, it appears semi-transparently and slides in the app, instead of pushing it
Down.
if (mhidestatusbarcheckbox.ischecked ()) {//fullscreen mode: Hides the status bar but does not hide the virtual key
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 is. 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 ()) {//Hide virtual key, click to appear
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 is 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 the 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 would *not* is cleared when the user interacts with the UI.
When the user swipes, the bars would 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);
LOG.I (TAG, "current height:" + decorview.getheight () + ", Width:" + decorview.getwidth ()); End_include (Set_ui_flags)


Immersivemode immersion mode of Androidのui experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.