简体   繁体   English

以编程方式在Android中禁用“返回”,“首页”和“最近”按钮

[英]Disable back, Home and Recent button in android programmatically

I am developing lock screen application in android. 我正在用android开发锁屏应用程序。

The problem is how to disable Back, Home and Recent button in the activity? 问题是如何在活动中禁用“返回”,“主页”和“最近”按钮?

I found that back button disable using: 我发现后退按钮禁用使用:

@Override
    public void onBackPressed() {
        return;
    }

But how to disable the others? 但是如何禁用其他?

Problem image: http://postimg.org/image/a0tnk7kr5/ 问题图片: http//postimg.org/image/a0tnk7kr5/

You have to override the Back action and return true to let the OS know that this action already handled and prevent executing the default action for that, which is closing the screen 您必须重写Back操作并返回true以使操作系统知道该操作已被处理,并阻止执行该操作的默认操作,即关闭屏幕

Your code is valid for API level 5, but for older then API 5 use this: 您的代码对API级别5有效,但对于API 5之前的版本,请使用以下代码:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
    // your code
    return true;
}

return super.onKeyDown(keyCode, event);
}

reference: Answer 参考: 答案

This question is asking about how to disable the Home and Recent buttons like the MXPlayer application when you click on the Lockscreen. 这个问题是关于单击锁定屏幕时如何禁用“ 主页”和“最近”按钮(如MXPlayer应用程序)的问题。 The accepted answer says that 被接受的答案说

Since you cannot override the Home button on Android device (at least no in the latest OS versions). 由于您无法覆盖Android设备上的“主页”按钮(在最新的OS版本中至少没有此功能)。 MX Player draws itself on top of your launcher when you "lock" the app and clicks on the Home button. 当您“锁定”应用程序并单击“主页”按钮时,MX Player会将自己绘制在启动器顶部。

and gives a details description how to do that. 并详细说明如何执行此操作。 Check it out here 在这里查看

实际上,您的触摸屏存在问题,即使您的屏幕部件仍在工作,您也可以下载(按钮救星)应用程序,这将为您的手机增加一个额外的首页和近期按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM