home键 捕捉

public void onAttachedToWindow ()
Since: API Level 5

Called when the main window associated with the activity has been attached to the window manager. See View.onAttachedToWindow() for more information.
See Also

    * onAttachedToWindow()

view plaincopy to clipboardprint?
@Override  
public void onAttachedToWindow() {  
    // TODO Auto-generated method stub  
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);  
    super.onAttachedToWindow();  
}  
@Override  
public boolean onKeyDown(int keyCode, KeyEvent event) {  
    // TODO Auto-generated method stub  
    switch(keyCode) {  
    case KeyEvent.KEYCODE_BACK:  
        Log.e("Test", "onKeyDown KEYCODE_BACK");  
        break;  
    case KeyEvent.KEYCODE_HOME:  
        Log.e("Test", "onKeyDown KEYCODE_HOME");  
        break;  
    }  
    return false;  

@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch(keyCode) {
case KeyEvent.KEYCODE_BACK:
Log.e("Test", "onKeyDown KEYCODE_BACK");
break;
case KeyEvent.KEYCODE_HOME:
Log.e("Test", "onKeyDown KEYCODE_HOME");
break;
}
return false;
}  

这样就可以屏蔽Home键了,但是一般不推荐屏蔽,这样会让用户抓狂的。



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fengqiaoyebo2008/archive/2011/03/20/6263536.aspx

你可能感兴趣的:(.net,Blog)