[Android] about the System toolbar and full-screen immersion mode

Source: Internet
Author: User

About System Bars, I've written several related articles before:

[Android] Gets the height of the system top status bar and bottom navigation bar (Navigation bar)
Some understanding of [Android] status bar
[Android] Lock screen

These three articles are written in order, originally only the application of the project, in fact, do not need to delve into, find the method and can be used up good. With the application of some in-depth design, we always want a better interface and experience, so some things can not just know the way to the end, it is to go into deep research. Through this process I think, from the application level, want to achieve a function is very simple, but if you want to achieve good, it is necessary to understand the designer's design ideas and the methods provided. The most straightforward way to understand a designer's idea is to look at the document. Of course, the understanding of the document can be further, to see how the Android source code is implemented, that is, from the application layer into the Framework layer. Familiarity with the Framework gives you the knowledge of the Linux kernel to understand the Android underlying implementation. Well, first put the attention on the application layer, after all, this is the simplest.

System Bars includes three bar:

    • Status bar, which is the bar at the top that displays information such as time, power, notifications, etc.
    • Navigation bar, bar with back key, home key, and recent key at the bottom
    • Action Bar, the top of the program can be added such as Search, menu bar

The operation of System Bar is to get the height, state, and set the display/hide state, before the two have written, this time the hidden Bar to write detailed points.

This address : http://www.cnblogs.com/rossoneri/p/4418770.html

Fade System Toolbar

Fade (dim-do not know this is appropriate) the effect of the toolbar is that the icons on the status bar and navigation bar become a light gray dot. The meaning of this is to let the user focus on the content of the program to display, to avoid excessive on-screen distracting user attention.

It may be said that this does not make much sense, but actually the user experience is a little bit of detail accumulated in all aspects. Sometimes users in the comparison of several apps will have a very obvious likes which do not like which, but let him specifically listed where the gap he is not listed. Most of the reasons for this are in these small details, but can not be said to feel. And since it has this function, it has the meaning of existence, then to understand how it is achieved.

Note that this method is only available in version 4.0 and above. When used, the size of the app content does not change, only the icons on the two bar are dimmed, and once you touch the bar area, all the icons appear and no longer disappear.

Method is simple, set system flag to System_ui_flag_low_profile

Getactivity (). GetWindow (). Getdecorview (). setsystemuivisibility (View.system_ui_flag_low_profile);

Note that once you touch the bar, the flag will be emptied, so the icon will not fade after the touch is finished. If you need to continue to achieve the fade effect, you can use View.onsystemuivisibilitychangelistener to monitor the state changes and then do the processing.

If you want to proactively clear the current system UI flag by code in some cases, you can use:

Getactivity (). GetWindow (). Getdecorview (). setsystemuivisibility (0);

As you can see from my previous article, 0 represents the default state, which is the flag that bar displays normally, namely:

 Public Static Final int system_ui_flag_visible = 0;

Hide Status Bar

In fact, the use of desalination is not many, and hide the Status Bar is more. Because you can free up more display space, you can provide a better user experience.

The following two images show the hidden status bar makes the program more intuitive and more comfortable to look at.

Note that the diagram on the left has an action bar, and if you do not show the status bar, hide the action bar, which is a suggestion for the design interface.

Setup method:

  1. Version 4.0 and below:
    1. Set in manifest:
      • < Application     ...    Android:theme= "@android: Style/theme.holo.noactionbar.fullscreen">     ... </ Application >

        This setting is simple and error-prone because the system already has an interface to render before instantiating the mainactivity, so the UI conversion will be smoother

    2. Set in code with WindowManager flags
      •  public  class  mainactivity extends   Activity {@Override  protected< /span> void   OnCreate (Bundle savedinstancestate { super  .oncreate (Savedinstancestate)        ;  //  If the Android version is lower than        Jellybean, use this call to hide the status bar.  if  (Build.VERSION.SDK_INT < 16) {GetWindow (). SetFlags (Windowmanager.layoutparams .        Flag_fullscreen, WindowManager.LayoutParams.FLAG_FULLSCREEN);    } setcontentview (R.layout.activity_main); }    ...}

        After the WindowManager flags are set, the flag is retained until they are cleaned with code. If you have already set Flag_fullscreen, you can use Flag_layout_in_screen to set activity LAYOUT using the currently available screen area, which prevents changes in the interface size when the status bar is displayed/hidden.

  2. Version 4.1 and above:

You can set the UI flags on a separate view level with the aforementioned setsystemuivisibility (), which take effect on the window.

View Decorview = GetWindow (). Getdecorview (); // Hide the status bar. int uioptions = view.system_ui_flag_fullscreen;decorview.setsystemuivisibility (uioptions); // Remember that should never show the action bar if the // status bar is hidden, so hide that too if necessary. ActionBar ActionBar = getactionbar (); Actionbar.hide ();

Attention:

    • Once the flag is set, the application needs to reset the flag to hide the bar. Add listener to do the processing
    • Setting the flag's code to write in different places has different effects. For example, if you set a hidden flag in the activity's OnCreate () method, the user presses the Home key, the status bar is displayed again, and then the application is opened, and status bar remains displayed. If it needs to be hidden, it needs to be set in the Onresume () or onwindowfocuschanged () method.
    • The Setsystemuivisibility () method is only valid in the visible view, such as setting the View.gone to no effect
    • Toggle view clears the flag of the current view setting

Show program content behind Status Bar

The previous article encountered this problem, but also bothered me for half a day, later found that the program can be displayed in the back of the status bar, the advantage is that the program's content size will not be displayed and hidden with the status bar changes.

Achieve this effect only with the set System_ui_flag_layout_fullscreen, while using system_ui_flag_layout_stable to ensure that the size is not changed

When you use the approach, it becomes your responsibility to ensure that critical parts of the Your app ' s UI (for example, th E built-in controls in a Maps application) don ' t end up getting covered by system bars. This could make your app unusable. In most cases you can handle this by adding the Android:fitssystemwindows attribute to your an XML layout file, set to True. This adjusts the padding of the parent viewgroup to leave space for the system windows. This is the sufficient for most applications. In some cases, however, your may need to modify the default padding to get the desired layout for your app. To directly manipulate how your content lays out relative to the system bars (which occupy a space known as the window ' s " Content insets "), override Fitsystemwindows (Rect insets). The Fitsystemwindows () method is called by the view hierarchy when the content insets for a window has changed, to allow The window to adjust its content accordingly. By overriding this method can handle the InseTS (and hence your app ' s layout) however you want. 
that's good to know.

Hide Navigation Bar

As a design suggestion, hide the navigation bar at the same time, but also to hide the status bar (of course, the status bar hides the action Bar is also hidden), of course, hidden or can be called at any time, so that you can use the entire screen space, to give users a better experience.

Use system_ui_flag_hide_navigation settings at 4.0 and later to hide both the status bar and NAVIGATION bar.

View Decorview = GetWindow (). Getdecorview (); // Hide both the navigation bar and the status bar. // System_ui_flag_fullscreen is only available on Android 4.1 and higher, but as a general rule, you should design your App to hide the status bar whenever your hide the navigation bar. int uioptions = view.system_ui_flag_hide_navigation              |  View.system_ui_flag_fullscreen;decorview.setsystemuivisibility (uioptions);

Note Refer to Hide status bar attention.

Of course, since the program content can be displayed behind the status bar, the same effect can be set on the Navigation bar. You can use System_ui_flag_layout_hide_navigation and system_ui_flag_layout_stable.

Use full-screen immersion mode

This is the 4.4 version of the new add mode, set the flag for system_ui_flag_immersive and system_ui_flag_immersive_sticky two kinds. Often used in conjunction with System_ui_flag_hide_navigation and System_ui_flag_fullscreen.

The effect of this mode is to hide the top and bottom two bar, while you in the range of bar click on the event will not be called out, which provides a great convenience for the operation of the program. You ask, since the Click event doesn't call bar, what if I want to use the bar function? This is also very simple, the finger is placed in the bar area, if the area of the status bar swipe down, or the other way up, so that the two bar can be called out. This operation is actually to clear the system_ui_flag_hide_navigation and System_ui_flag_fullscreen, so it will be visible, at the same time will trigger the corresponding Listener.

Previously said there are two kinds of IMMERSIVE and Immersive_sticky, the former is the bar call out after no longer disappear, the latter is the bar called out a few seconds after the disappearance, the latter does not trigger Listener.

Also, setting fullscreen will make the status bar appear translucent and the background of status bar is black in normal state. See:

Figure 1: normal state. Figure 2: There will be a hint when entering immersive full-screen mode for the first time.

Options for IMMERSIVE and Immersive_sticky:

    • If you are doing a reading, magazine software or watching news software, it is recommended to use the IMMERSIVE logo, with System_ui_flag_fullscreen and system_ui_flag_hide_navigation. Because users may frequently need to use UI buttons while browsing content, they do not want to be disturbed.
    • If you want users to experience immersive mode, use the STICKY flag
    • If the user interaction is very small like a video player, do not use IMMERSIVE, the content of the previous write can meet the requirements

  

When using the IMMERSIVE flag, the hidden bar will always be displayed, then you need to set some flags to keep the software content size unchanged, such as System_ui_flag_hide_navigation and system_ui_flag_layout_stable, Also pay attention to the hidden action Bar.

//This snippet hides the system bars.Private voidHidesystemui () {//Set the IMMERSIVE flag. //Set the content to appear under the system bars so the content//doesn ' t resize when the system bars hide and show.mdecorview.setsystemuivisibility (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|view.system_ui_flag_immersive);}//This snippet shows the system bars. It does the removing all the flags//Except for the ones, the content appear under the system bars.Private voidShowsystemui () {mdecorview.setsystemuivisibility (view.system_ui_flag_layout_stable|view.system_ui_flag_layout_hide_navigation|view.system_ui_flag_layout_fullscreen);}

The following is the program window to receive focus when set Immersive_sticky as follows, in fact, combined with some of the previously mentioned methods, their own combination can achieve good results.

@Override Public voidOnwindowfocuschanged (BooleanHasfocus) {        Super. onwindowfocuschanged (Hasfocus); if(Hasfocus) {decorview.setsystemuivisibility (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|view.system_ui_flag_immersive_sticky);}}

Response to changes in the System toolbar display

Register a View.onsystemuivisibilitychangelistener to make the interface change synchronously, you can add the following code in the OnCreate () method:

View Decorview =GetWindow (). Getdecorview ();d Ecorview.setonsystemuivisibilitychangelistener (NewView.onsystemuivisibilitychangelistener () {@Override Public voidOnsystemuivisibilitychange (intvisibility) {        //Note that system bars would only be "visible" if none of the//Low_profile, hide_navigation, or fullscreen flags is set.        if((visibility & view.system_ui_flag_fullscreen) = = 0) {            //todo:the system bars is visible. make any desired//adjustments to your UI, such as showing the action bar or//Other navigational controls.}Else {            //todo:the System bars is not visible. make any desired//adjustments to your UI, such as hiding the action bar or//Other navigational controls.        }    }});

Above may have the understanding error or the error that I have not found in the test, if you see what the problem after the notice, please leave feedback, thank you.

[Android] about the System toolbar and full-screen immersion mode

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.