【Android进阶学习】屏蔽,捕获Home键
来源:IT的点点滴滴 责任编辑:栏目编辑 发表时间:2013-07-01 03:58 点击:次
在Level5以上(包含)中,Activity类中的方法:public void onAttachedToWindow ()就能对Home键进行捕获。具体代码如下:
MainActivity.java
- 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) {
-  
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>