0

How can I enable or disable the home button on Android tablets?

Michael Petrotta
  • 58,479
  • 27
  • 141
  • 176
Nas
  • 2,088
  • 1
  • 17
  • 35

3 Answers3

2

Overriding the Home button - how do I get rid of the choice?

you can, but it's dangerous

also, this question has been asked multiple times in the past

Community
  • 1
  • 1
David
  • 302
  • 2
  • 16
1

By implementing Overided methods onAttachedToWindow() and onKeyDown() it's work fine.

@Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        MainActivity.this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);           
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_HOME) {
            Log.d("Home Button", "Clicked");
        }
        if (keyCode == KeyEvent.KEYCODE_BACK) {

            finish();
        } 
        return false;
    };

Without overriding onAttachedToWindow method KEYCODE_HOME doesn't work.

Note:Home key press is handled by the framework and is never delivered to applications.

This is a flaw in version <4.0 and is not working from ICS.

Nas
  • 2,088
  • 1
  • 17
  • 35
-1

Try this code.

@Override
public void onAttachedToWindow() {
    Log.i("TESTE", "onAttachedToWindow");
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();
}