Disable system home in android 4.0
2.2 disable the system home key.
Recently, the project has a requirement to disable all system keys, such as menu, home, and back. At the same time, you also want to click the response and view pop-up. That is, the UI part should be normal.
The back key is disabled by onKeyDown.
I personally think that the simplest writing method can be found:
Http://blog.csdn.net/yiding_he/article/details/38527813
The key here is to disable the system home key after 4.0.
After searching for the Internet for a long time, it is basically useless. Because it is said that due to system security reasons, the android system absorbed the event (home, menu) at the framework layer and did not distribute it to the application layer.
The Menu key can't be disabled for security reasons, this key is handled by the framework and is never delivered to applications.
Http://stackoverflow.com/questions/15459407/disable-home-button-in-android-4-0
Look, there is no way for the stack overflow of foreigners.
When I was close to disappointment, I randomly clicked github, ghost.
More importantly, this great god is even Chinese. Too good.
Here, I will not elaborate on how the great gods implement it. The secret is to create an OverlayDialog and set some parameters for it, such as FLAG_SHOW_WHEN_LOCKED and FLAG_NOT_TOUCH_MODAL.
If you want to study, please download the source code.
Here we will only talk about the usage:
1. To the https://github.com/shaobin0604/Android-HomeKey-Locker, download the code of the great god.
2. Put HomeKeyLocker. java in HomeLockLib under your Util package.
3. Copy the OverlayDialog related part of styles in HomeLockLib to your styles.
4. Add it to your own AndroidManifest
5. The new HomeKeyLocker object is located at the place where you want to lock the key.
private HomeKeyLocker mHomeKeyLocker;mHomeKeyLocker = new HomeKeyLocker();
Use the lock key later:
MHomeKeyLocker. lock (mActivity. this );
Unlock:
MHomeKeyLocker. unlock ();
6. Add the following to your destroy method:
@Overrideprotected void onDestroy() {super.onDestroy();mHomeKeyLocker.unlock();mHomeKeyLocker = null;}
In this way, you can have fun.