[Work accumulation] Android:hide Navigation bar Hidden navigation bar

Source: Internet
Author: User

Https://developer.android.com/training/system-ui/navigation.html

1View Decorview =GetWindow (). Getdecorview ();2 //Hide both the navigation bar and the status bar.3 //System_ui_flag_fullscreen is only available on Android 4.1 and higher, but as4 //A general rule, you should design your app to hide the status bar whenever you5 //hide the navigation bar.6 intUioptions =view.system_ui_flag_hide_navigation7|View.system_ui_flag_fullscreen;8Decorview.setsystemuivisibility (uioptions);

Where you set the UI flags makes a difference. If you hide the system bars in your activity ' s onCreate () method and the user presses Home, the system bars would reappear. When the user reopens the activity, OnCreate () won ' t get called, so the system bars would remain visible. If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in Onresume () or Onwindowfocuschanged ().

Https://developer.android.com/training/system-ui/immersive.html

1 //This snippet hides the system bars.2 Private voidHidesystemui () {3     //Set the IMMERSIVE flag.4     //Set the content to appear under the system bars so the content5     //doesn ' t resize when the system bars hide and show.6 mdecorview.setsystemuivisibility (7 view.system_ui_flag_layout_stable8|view.system_ui_flag_layout_hide_navigation9|View.system_ui_flag_layout_fullscreenTen| View.system_ui_flag_hide_navigation//Hide nav Bar One| View.system_ui_flag_fullscreen//Hide Status bar A|view.system_ui_flag_immersive); - } -  the //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); A}

Note:if the auto-hiding behavior of Immersive_sticky but need to show your own UI controls as well, just use IMM Ersive combined with handler.postdelayed () or something similar to re-enter immersive mode after a few seconds.

Current requirement:

    • Hide Navigation bar on startup
    • Auto Hide Navigation Bar (Immersive_sticky + posedelayed ())

Implementation:

1     //////////////////////////////////////////////////////////////////////////2      Public voidHidenavigationbar () {3         intUiflags =view.system_ui_flag_layout_stable4|view.system_ui_flag_layout_hide_navigation5|View.system_ui_flag_layout_fullscreen6| View.system_ui_flag_hide_navigation//Hide nav Bar7| View.system_ui_flag_fullscreen;//Hide Status bar8 9         if(Android.os.Build.VERSION.SDK_INT >= 19 ){
TenUiflags |= 0x00001000;//system_ui_flag_immersive_sticky:hide navigation bars-compatibility:building API level are lower thatn, use magic Number directly for higher API target level One}Else { AUiflags |=View.system_ui_flag_low_profile; - } - the GetWindow (). Getdecorview (). setsystemuivisibility (uiflags); - } - - + ////////////////////////////////////////////////////////////////////////// - @Override + protected voidonCreate (Bundle savedinstancestate) { A ... at Hidenavigationbar (); - Super. OnCreate (savedinstancestate); - ... - } - - ////////////////////////////////////////////////////////////////////////// in @Override - Public voidOnwindowfocuschanged (BooleanHasfocus) { to Super. onwindowfocuschanged (hasfocus); + if(hasfocus) { - Hidenavigationbar (); the } *}

Note:postdelayed is not yet added, because on tested devices, navigation bar would auto hide for some secs.

ADD postdelayed () event to manully Auto Hide nav bar if needed.

[Work accumulation] Android:hide Navigation bar Hidden navigation bar

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.