Android Project Combat (41): Game and video type apply status bar immersive effects

Source: Internet
Author: User

Original: Android Project Combat (41): Game and video type apply status bar immersive effect

  Demand:

Mobile app, when playing a game or full screen watching video will find that this time the top of the mobile phone status bar is not displayed, when we swipe down from the top of the phone or the bottom of the phone to swipe up, the status bar will be displayed, if a short period of time without action, the status bar will be hidden again.

  

  Implementation code:

@Override
protected void OnCreate (Bundle savedinstancestate) {
   Super.oncreate (savedinstancestate);
   Setcontentview (R.layout.activity_main);
}

@Override
public void Onwindowfocuschanged (Boolean hasfocus) {
   Super.onwindowfocuschanged (Hasfocus);
   if (Hasfocus && Build.VERSION.SDK_INT >=) { //If there is focus, description is currently interacting with the user and sdk_int>=19 only android4.4+ In order to support immersive effects
View Decorview = GetWindow (). Getdecorview ();
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);
}
}

  Effect:

 Code Explanation:

1, Onwindowfocuschanged (Boolean Hasfocus) method

     Activity life cycle, can be understood as the way to go to this method, the activity is the real meaningof the display/truefalse

 2, Getwindow.getdecorview () method, get the top view of window interface

Decorview is the topmost view of the entire window interface. Second, Decorview only one child element is linearlayout.  Represents the entire window interface, including the notification bar, the title bar, the content display bar three block area.    There are two framelayout elements in LinearLayout. Display the interface for the title bar. Only one TextView displays the name of the app.    You can also customize the title bar, and the post-loaded custom title bar view will be added to the framelayout. Display the interface for the content bar. The Setcontentview () method loads the layout interface and joins it.

    

    Note:

and activity full screen display difference is that if the phone has a virtual navigation bar (ie, virtual back, home button), the full screen will always be displayed, and the above method, the navigation bar and status bar synchronization display, the above requirements with full-screen implementation of the effect is not correct.

Android Project Combat (41): Game and video type apply status bar immersive effects

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.