Android 之屏蔽,捕获Home键

package com.lingdududu.test; 
import android.app.Activity; 
import android.os.B
undle;  import android.view.KeyEvent;
  import android.view.WindowManager; 
 import android.widget.Toast; 
  public class MainActivity extends Activity { 
     /** Called when the activity is first created. */  
   private boolean catchHomeKey = false;     
 public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);        
  setContentView(R.layout.main);      }    
        @Override     public void onAttachedToWindow() {          // TODO Auto-generated method stub          if (!catchHomeKey) {              this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);          }          super.onAttachedToWindow();      }       @Override     public boolean onKeyDown(int keyCode, KeyEvent event) {          // TODO Auto-generated method stub          if (keyCode == KeyEvent.KEYCODE_HOME) {              Toast.makeText(MainActivity.this, "你点击了HOME键", Toast.LENGTH_LONG).show();          }          return super.onKeyDown(keyCode, event);      }  } 

你可能感兴趣的:(android)