Disable the Android system home key

Source: Internet
Author: User

Disclaimer: Resources are from Https://github.com/shaobin0604/Android-HomeKey-Locker, can be accessed directly from this address, or access my resources http://download.csdn.net/ detail/youshenxuzuo/8575529 download, long-term effective.


In project development, it may be necessary to block the Android virtual keys, where the return key is relatively easy to disable, the following two ways to solve:

@Override Public    boolean onKeyDown (int keycode, keyevent event) {  if (keycode = = keyevent.keycode_back) {      return  true;}  Return  Super.onkeydown (KeyCode, event);     
Or

@Overridepublic void onbackpressed () {}

Next explain how to block the home key:

1, download the above resources, unzip the file;

2. Copy the Homekeylocker.java file to your project;

3.

<style name= "Overlaydialog" parent= "@android: Style/theme.dialog" >        <item name= "Android: Windowbackground "> @android:color/transparent</item>        <item name=" Android:windowframe "> @null </item>        <item name= "Android:windownotitle" >true</item>        <item name= "Android: Windowisfloating ">true</item>        <item name=" Android:windowistranslucent ">false</item>        <item name= "android:backgrounddimenabled" >false</item>    </style>
Copy to your styles.xml file;

4, will

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

Copied to the Androidmanifest.xml file;

5. Add code to the activity file that you want to block:

Private Homekeylocker Mhomekeylocker;

public void OnCreate (Bundle parambundle) {<span style= "white-space:pre" ></span>mhomekeylocker = new Homekeylocker (); <span style= "White-space:pre" ></span>mhomekeylocker.lock (LoginActivity.this);}

protected void OnDestroy () {<span style= "White-space:pre" ></span>mhomekeylocker.unlock (); Mhomekeylocker = Null;super.ondestroy ();}

The 5 steps above can be implemented to disable the home key.

Measured available equipment:

Android 4.4.4

Samsung TAB4

  • Android 4.4.2
    • CM11 (Google Nexus S, Moto Defy)
  • Android 4.0.3
    • Moto XT910
    • Huawei C8812
  • Android 4.0.4
    • ZTE v889m
    • Android 2.3.5
      • HTC Desire S (Sense 3.0)
  • Android 2.3.5
    • HTC Desire S (Sense 3.0)
Devices not available
    • MIUI
    • Flyme

Disable the Android system home key

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.