Android Development Close the virtual button, the bottom navigation bar

Source: Internet
Author: User

In the development of Android, encountered a series of large and small problems, one of which is to block the bottom of the entity keys, I find a lot of blog also tried many ways, but always can not block home key, later saw a blog said after Android 4.0, the screen bottom home button must be anti-compilation , modify the Android bottom native code, so I gave up. Needless to say, I'll first share a way to block Android virtual keys, and the simplest to block Android's Back button, for all versions (not tested, feel like this):

1. Android Screen Back button

Just rewrite the OnKeyDown method, and the code is as follows:

@Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {        if(KeyCode = =keyevent.keycode_back) {Toast.maketext (mainactivity). This, "µ»ø¼üòñ±»½ûóã ...", Toast.length_short). Show (); return true;//return True and false I have tried, can block, the reason is unknown, want to know can tell me, thank you        }return Super. OnKeyDown (KeyCode, event); }

2. Android Hidden Virtual navigation bar (requires system privileges)

You need to include the following permissions in Androidmanifest.xml:

<android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>

Then is the code to close the bottom navigation bar, I encapsulated into a class, just need to call the method in the OnCreate method is the line, the class is as follows:

 Packagecom.jd.nanapptwo.utils;ImportAndroid.os.Build;/*** Turn off display navigation bar*/ Public classClosebarutil {/*** Close the bottom navigation bar*/     Public Static voidClosebar () {Try {            //requires root privilegesBuild.version_codes VC =Newbuild.version_codes (); Build.version VR=Newbuild.version (); String ProcID= "79"; if(VR. Sdk_int >=VC. Ice_cream_sandwich) {ProcID= "42";//ICS and newer            }            //requires root privilegesProcess proc =runtime.getruntime (). EXEC (Newstring[]{"Su",                            "-C",                            "Service Call activity" +ProcID+ "S16 Com.android.systemui"});// wasproc.waitfor (); } Catch(Exception e) {e.printstacktrace (); }    }    /*** Show bottom navigation bar*/     Public Static voidShowbar () {Try{Process proc=runtime.getruntime (). EXEC (Newstring[]{"AM", "StartService", "-N",                            "Com.android.systemui/. Systemuiservice "});        Proc.waitfor (); } Catch(Exception e) {e.printstacktrace (); }    }}

I hope the above method will be helpful to you.

Android Development Close the virtual button, the bottom 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.