How Android fits the bottom virtual keys

Source: Internet
Author: User

---restore content starts---

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Recently, when the project was adapted to find some (such as Huawei Mobile phone) in the presence of the bottom of the virtual key mobile phone because the existence of virtual keys to block some of the interface, because the need for full-screen display, so call the virtual key hiding method to hide, but found that the following problems:

    • Manual operation hides the virtual key and a long white area appears
    • Do not hide automatically
    • Slide out of the status bar after the virtual button is also out, the status bar hidden after the virtual but not to hide behind
    • On the device without the virtual keys affect the Surfaceview full-screen display map (originally full-screen display of the picture in the cut out and then come in when the small screen display)

Through Google a lot of ways and try to finally solve the problem, to achieve the following effect:

    • Virtual keys are automatically hidden every time you enter the interface
    • Manually slide out the virtual keys to automatically hide when the screen is not being manipulated
    • When you slide out of the status bar, the virtual keys will be followed, and the status bar should be processed to automatically hide when it is not working.

The specific code is as follows:

PublicClassTestactivityExtendsappcompatactivity {Private View Decorview;@OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_test);Get top level View Decorview = GetWindow (). Getdecorview (); }@OverrideProtectedvoidOnStart () {Call config init ();Super.onstart (); }PrivatevoidInit () {int flag = View.system_ui_flag_layout_stable | view.system_ui_flag_layout_hide_navigation | View.system_ui_flag_layout_fullscreen | View.system_ui_flag_hide_navigationHide | View.system_ui_flag_fullscreenHide Status Bar | View.system_ui_flag_immersive_sticky;Determine if the current version is above 4.0 and there are virtual keys, otherwise do not operateif (Build.VERSION.SDK_INT <19 | | !checkdevicehasnavigationbar ()) {Be sure to determine if there is a button, otherwise the phone call without the key will affect other functions. As not previously considered, resulting in a full screen of the picture into a small screen display.Return }else {Gets the attribute decorview.setsystemuivisibility (flag); } }/** * Determine if there are virtual keys *@return */PublicBooleanCheckdevicehasnavigationbar () {Boolean Hasnavigationbar =False Resources rs = getresources ();int id = rs.getidentifier ("Config_shownavigationbar","BOOL","Android");if (ID >0) {Hasnavigationbar = Rs.getboolean (ID);}try {class<?> Systempropertiesclass = Class.forName ("Android.os.SystemProperties"); Method m = Systempropertiesclass.getmethod ( "get", string.class); String navbaroverride = (string) m.invoke (Systempropertiesclass,  "Qemu.hw.mainkeys"); Span class= "Hljs-keyword" >if ( "1". Equals (Navbaroverride)) {Hasnavigationbar = FALSE; } else if ( "0". Equals ( Navbaroverride) {Hasnavigationbar = true;}} catch (Exception e) {} return Hasnavigationbar;}  @Override public boolean ontouch (View V, motionevent event) {return FALSE; } 

Note: There are times when you need to manually call the init () configuration method in the code above to hide the key. such as pop-up dialog when the virtual button will come out, this time to manually call the hidden, as well as pop-up keyboard and so on.

Record, and later encounter such problems can be used for reference.

---restore content ends---

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Recently, when the project was adapted to find some (such as Huawei Mobile phone) in the presence of the bottom of the virtual key mobile phone because the existence of virtual keys to block some of the interface, because the need for full-screen display, so call the virtual key hiding method to hide, but found that the following problems:

    • Manual operation hides the virtual key and a long white area appears
    • Do not hide automatically
    • Slide out of the status bar after the virtual button is also out, the status bar hidden after the virtual but not to hide behind
    • On the device without the virtual keys affect the Surfaceview full-screen display map (originally full-screen display of the picture in the cut out and then come in when the small screen display)

Through Google a lot of ways and try to finally solve the problem, to achieve the following effect:

    • Virtual keys are automatically hidden every time you enter the interface
    • Manually slide out the virtual keys to automatically hide when the screen is not being manipulated
    • When you slide out of the status bar, the virtual keys will be followed, and the status bar should be processed to automatically hide when it is not working.

The specific code is as follows:

PublicClassTestactivityExtendsappcompatactivity {Private View Decorview;@OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_test);Get top level View Decorview = GetWindow (). Getdecorview (); }@OverrideProtectedvoidOnStart () {Call config init ();Super.onstart (); }PrivatevoidInit () {int flag = View.system_ui_flag_layout_stable | view.system_ui_flag_layout_hide_navigation | View.system_ui_flag_layout_fullscreen | View.system_ui_flag_hide_navigationHide | View.system_ui_flag_fullscreenHide Status Bar | View.system_ui_flag_immersive_sticky;Determine if the current version is above 4.0 and there are virtual keys, otherwise do not operateif (Build.VERSION.SDK_INT <19 | | !checkdevicehasnavigationbar ()) {Be sure to determine if there is a button, otherwise the phone call without the key will affect other functions. As not previously considered, resulting in a full screen of the picture into a small screen display.Return }else {Gets the attribute decorview.setsystemuivisibility (flag); } }/** * Determine if there are virtual keys *@return */PublicBooleanCheckdevicehasnavigationbar () {Boolean Hasnavigationbar =False Resources rs = getresources ();int id = rs.getidentifier ("Config_shownavigationbar","BOOL","Android");if (ID >0) {Hasnavigationbar = Rs.getboolean (ID);}try {class<?> Systempropertiesclass = Class.forName ("Android.os.SystemProperties"); Method m = Systempropertiesclass.getmethod ( "get", string.class); String navbaroverride = (string) m.invoke (Systempropertiesclass,  "Qemu.hw.mainkeys"); Span class= "Hljs-keyword" >if ( "1". Equals (Navbaroverride)) {Hasnavigationbar = FALSE; } else if ( "0". Equals ( Navbaroverride) {Hasnavigationbar = true;}} catch (Exception e) {} return Hasnavigationbar;}  @Override public boolean ontouch (View V, motionevent event) {return FALSE; } 

Note: There are times when you need to manually call the init () configuration method in the code above to hide the key. such as pop-up dialog when the virtual button will come out, this time to manually call the hidden, as well as pop-up keyboard and so on.

Record, and later encounter such problems can be used for reference.

How Android fits the bottom virtual keys

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.