标签:
返回键
public void onBackPressed() {
// TODO Auto-generated method stub
Toast toast=Toast.makeText(config.this, "此键坏掉了。。。\n按旁边的吧!", 3000);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
搜索键
@Override
public boolean onSearchRequested() {
// TODO Auto-generated method stub
Toast.makeText(config.this, "我一直是坏掉的。。。", 1000).show();
return super.onSearchRequested();
}
菜单键
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(0, 0, 0, "退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case 0:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
<SPAN style="COLOR: #ff0000">先禁止Home键,再在onKeyDown里处理按键值,点击Home键的时候就把程序关闭</SPAN>
public boolean onKeyDown(int keyCode, KeyEvent event)
{
// TODO Auto-generated method stub
if(KeyEvent.KEYCODE_HOME==keyCode)
android.os.Process.killProcess(android.os.Process.myPid());
return super.onKeyDown(keyCode, event);
}
@Override
public void onAttachedToWindow()
{
// TODO Auto-generated method stub
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
加权限禁止Home键
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
标签:
原文地址:http://www.cnblogs.com/iverson-weng/p/5108696.html