Android Project Practice (): immersive effect on the status bar of game and video applications, and android practice

Source: Internet
Author: User

Android Project Practice (): immersive effect on the status bar of game and video applications, and android practice

Requirements:

Mobile app, when playing a game or watching a video in full screen, you will find that the status bar at the top of the mobile phone is not displayed at this time. When we slide down from the top of the mobile phone or move up at the bottom of the mobile phone, the status bar is displayed. If the operation is not performed for a few seconds, the status bar is 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> = 19) {// if there is a focus, it indicates that the current interaction with the user and SDK_INT> = 19 only Android4.4 + supports 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

The Activity life cycle can be understood as that, when this method is reached, the activity is truly displayed/disappears in the interaction layer. When the activity is displayed on the top of the stack and interacts with the user, there is a focus. hasFocus is true. When the activity exits from the top of the stack and does not interact with the user, there is no focus, hasFocus is false.

 

 

2. getWindow. getDecorView () method to obtain the top-level View of the Window interface

1. DecorView is the top View of the entire Window interface. 2. DecorView has only one child element, LinearLayout. Indicates the entire Window interface, including the notification bar, title bar, and content display bar. 3. LinearLayout contains two FrameLayout sub-elements. (20) The title bar display interface. Only one TextView displays the application name. You can also customize the title bar. The loaded custom title bar View will be added to FrameLayout. (21) shows the content bar. Is the layout interface loaded by the setContentView () method.

 

 

    

Note:

The difference between full screen display and Activity is that if the mobile phone has a virtual Navigation Bar (that is, the virtual back, home Key), the full screen will always be displayed, the above requirement is incorrect when full screen is used.

 

Related Article

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.