当前位置: 代码迷 >> Android >> Android 之障蔽,捕获Home键
  详细解决方案

Android 之障蔽,捕获Home键

热度:91   发布时间:2016-04-28 04:21:26.0
Android 之屏蔽,捕获Home键
package com.lingdududu.test; import android.app.Activity; import android.os.Bundle;  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);      }  } 
  相关解决方案