public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000; //需要自己定义标志
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//关键代码
setContentView(R.layout.main);
}
再重写onKey事件即可。
@Override
public boolean onKeyDown( int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == event. KEYCODE_HOME) {
return true;
}
return super.onKeyDown(keyCode, event);
}
都不行