简体   繁体   English

android应用程序运行时如何忽略设置或其他按钮功能

[英]How to ignore settings or other button function when android application is running

The question is simple, How to ignore settings or other button function when android application is running ? 问题很简单,Android应用程序运行时如何忽略设置或其他按钮功能? We have an application, everything is fine, but when we press the button (hardware on our mobile phone) the application closes with error (Unfortunately, application has stopped) We just want to ignore the settings button and close the application when the "back" (<-) button is pressed. 我们有一个应用程序,一切都很好,但是当我们按下按钮(手机上的硬件)时,该应用程序会错误关闭(不幸的是,应用程序已停止)。我们只想忽略设置按钮,而在“返回“(<-)按钮被按下。 Thank you for your answers. 谢谢您的回答。

In your main activity simply override onKeyDown. 在您的主要活动中,只需重写onKeyDown。

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK)
           finish();
}

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

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