屏蔽掉返回键,menu键,Home键

public class LockActivity extends Activity{
	private  static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//关键代码 
		setContentView(R.layout.activity_main);
		
	}
	@SuppressWarnings("static-access")
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if(keyCode==event.KEYCODE_BACK){
			return true;
		}
		if(keyCode==event. KEYCODE_HOME){
			return true;
		}
		if(keyCode == KeyEvent.KEYCODE_MENU) {//MENU键
	        //监控/拦截菜单键
	         return true;
	    }     
		return super.onKeyDown(keyCode, event);
	}
}

你可能感兴趣的:(android开发)