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