@Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if(keyCode == KeyEvent.KEYCODE_BACK) 
        { //监控/拦截/屏蔽返回键
            dialog();
    
            return false; 
            
        } else if(keyCode == KeyEvent.KEYCODE_MENU) 
        {
            if(isShowButton)
            {
                rly.setVisibility(View.VISIBLE);
                isShowButton = false;
                
            }else
            {
                rly.setVisibility(View.GONE);
                isShowButton = true;
            }
     
            return false;
            
        } else if(keyCode == KeyEvent.KEYCODE_HOME) 
        {
            //由于Home键为系统键,此处不能捕获,需要重写onAttachedToWindow()
  
            return false;
        }
        return super.onKeyDown(keyCode, event);
     }
    
    
    protected void dialog() 
    { 
        AlertDialog.Builder builder = new Builder(WebActivity.this); 
        builder.setMessage("确定要退出吗?"); 
        builder.setTitle("提示"); 
        builder.setPositiveButton("确认", 
        new android.content.DialogInterface.OnClickListener() 
        { 
            public void onClick(DialogInterface dialog, int which) 
            { 
                dialog.dismiss(); 
                WebActivity.this.finish(); 
            } 
        }); 
        
        builder.setNegativeButton("取消", 
        new android.content.DialogInterface.OnClickListener() 
        { 
            public void onClick(DialogInterface dialog, int which) 
            { 
                dialog.dismiss(); 
            } 
        }); 
        
        builder.create().show(); 
    } 
    
    
    /*
    // 拦截/屏蔽系统Home键
    public void onAttachedToWindow() 
    { 
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 
        super.onAttachedToWindow(); 
    }
    */

 

posted on 2014-05-26 17:45  瓦楞球  阅读(9535)  评论(0编辑  收藏  举报