How to hide a virtual key (navigation bar) on Android 4.0

Source: Internet
Author: User

In android4.0, Some APIs are added, including how to hide virtual keys (navigation bar). In this way, you can set parameters to hide virtual keys when writing a game or a video player to achieve the best effect, the premise is that the mobile phone is equipped with a virtual button, as shown in the box below. Take a look at the official android4.0 API instructions to understand.
Controls for system UI visibility

Since the early days of Android, the system has managed a UI component known asStatus Bar, Which resides at the top of handset devices to deliver information such as the carrier signal, time, notifications, and so on. Android 3.0 added
TheSystem barFor tablet devices, which resides at the bottom of the screen to provide system navigation controls (home, back, and so forth) and also an interface for elements traditionally provided by the status bar. in Android 4.0, the system provides
A new type of system UI calledNavigation Bar. You might consider the navigation bar a re-tuned version of the system bar designed for handsets-it provides navigation controls for devices that don't have hardware counterparts for navigating
System, but it leaves out the system bar's notification UI and setting controls. As such, a device that provides the navigation bar also has the status bar at the top.

To this day, you can hide the status bar on handsets using the flag_fullscreen flag.
In Android 4.0, the APIs that control the system bar's visibility have been updated to better reflect the behavior of both the system bar and navigation bar:

  • The system_ui_flag_low_profile flag replaces the status_bar_hidden flag. When set, this flag enables "low
    Profile "mode for the system bar or navigation bar. navigation buttons dim and other elements in the system bar also hide. enabling this is useful for creating more immersive games without distraction for the System navigation buttons.
  • The system_ui_flag_visible flag replaces the status_bar_visible flag to request the system bar or navigation
    Bar be visible.
  • The system_ui_flag_hide_navigation is a new flag that requests the navigation bar hide completely.
    Be aware that this works only forNavigation BarUsed by some handsets (it doesNotHide the system bar on tablets). The navigation bar returns to view as soon as the system variables ES user input. As such, this mode is useful primarily
    For video playback or other cases in which the whole screen is needed but user input is not required.

You can set each of these flags for the system bar and navigation bar by calling setsystemuivisibility () on
Any view in your activity. the Window Manager combines (or-together) all flags from all views in your window and apply them to the system UI as long as your window has input focus. when your window loses input focus (the user navigates away from your app,
Or a dialog appears), your flags cease to have effect. Similarly, if you remove those views from the view hierarchy their flags no longer apply.

To synchronize other events in your activity with visibility changes to the system UI (for example, hide the action bar or other UI controls when the system UI hides), you should register a view. onsystemuivisibilitychangelistener
Be notified when the visibility of the system bar or navigation bar changes.

See the overscanactivity class for a demonstration of different system
Ui options.

After reading this, write a test example and try it. OK ~

    import android.app.Activity;    import android.os.Bundle;    import android.view.View;    import android.view.View.OnClickListener;    public class HideTestActivity extends Activity implements OnClickListener{     View main ;        /** Called when the activity is first created. */        @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            main = getLayoutInflater().from(this).inflate(R.layout.main, null);            main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);            main.setOnClickListener(this);            setContentView(main);        }     @Override     public void onClick(View v) {      int i = main.getSystemUiVisibility();      if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {       main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);      } else if (i == View.SYSTEM_UI_FLAG_VISIBLE){       main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);      } else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {       main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);      }     }    }

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.