2016-01-13 144 views
0

我正在开发一个锁屏应用程序,到目前为止已经实现了应用程序工作所需的一切。如何禁用Android 4.0以上版本的Home/Menu按钮?

但我无法禁用在Android设备中虚拟以及虚拟软件可用的主页/菜单按钮。我已经在SO和其他网站上经历了所有可能的答案,但无法实现。

是否有任何测试和工作的解决方法? 在此先感谢。

回答

0

一种方法是显示一个对话框,其中LayoutParams类型设置为TYPE_SYSTEM_ERROR,并将此对话框的所有者设置为您的“锁定屏幕”活动以阻止主页按钮。

这里是一个如何可以做到这一点的例子: 更新:看起来像这样只预Android的4 + https://github.com/Joisar/LockScreenApp/blob/master/LockScreenApp/src/com/mehuljoisar/lockscreen/utils/LockscreenUtils.java

另一种方式的工作原理是直接添加contentView的窗口管理器,其中LayoutParams类型设置为TYPE_SYSTEM_ERROR

... 
onCreate(){ 

    //setContentView(R.layout.main_content); 
    //instead add a View directly to the WindowManager 
    View contentView = View.inflate(this, R.layout.main_content, null); 
    LayoutParams lockLayoutParams = new LayoutParams(); 
      lockLayoutParams.width = LayoutParams.MATCH_PARENT; 
      lockLayoutParams.height = LayoutParams.MATCH_PARENT; 
      lockLayoutParams.type = LayoutParams.TYPE_SYSTEM_ERROR; 

      //LOCK 
      getWindowManager().addView(contentView, lockLayoutParams); 

... 
      //UNLOCK 
      getWindowManager().removeView(contentView); 

缺点我有这种方法是,它看起来不支持更复杂的看法。我在片段等得到了很多闪烁的与列表视图

这何处使用示例项目:

https://github.com/Chin-Z/ArcherKeyguard/blob/master/src/com/lovewuchin/app/archerkeyguard/util/LockLayer.java

https://github.com/radames/ScreenLock-Android/blob/master/src/com/eva/me/mysquarescreenlock/lockutil/LockLayer.java

更多的答案similiar的问题在这里:How to disable Home and other system buttons in Android?

+0

我尝试过使用它,但未能如愿。它也只会阻止虚拟主键? @TouchBoarder –

+0

当我尝试它阻止了硬主页按钮,但这是在4.1的三星。我将在稍后与一个项目进行测试,看看它是否仍然有效? – TouchBoarder

+0

非常感谢... –