Does Android application development Guideline allow disabling Default Menu and back button for particular application?

吃可爱长大的小学妹 提交于 2019-12-23 00:49:24

问题


In my application there are some buttons that are very near to that device default back button and Menu Button. Thus I got problem while pressing that My application button which are near to Menu and Back button.

So for that application purpose I want to disable the default back and Menu Button.

So does Android Application development Guideline allow if we want to disable the back and Menu Button during particular application? If yes then how is it possible?

Thanks.


回答1:


So is Android Application development Guideline allow if we want to disable the back and Menu Button during perticular application?

The guideline of programming for any OS (Windows, Mac, iOS, Android etc.) is don't break the default behaviour.

A user will expect that your App supports the default behaviour of the device he/she is using and in most cases bought the device for that very reason: He/she enjoys the default behaviour. If he/she wanted another type of user interaction, he/she would have bought another type of device.

In my application there are some buttons that are very near to that device default back button and Menu Button

As long as your button is on the screen, I don't see how it can become a problem. If however it in someway is a problem, a better solution than overriding default behaviour is to move or enlarge your buttons to make it easier for the user to hit them.

If yes then how it is possible?

Yes, it can be done.

To disable the back button, simply override onBackPressed() in whatever Activity the problem occurs and leave the implementaion of it empty:

public void onBackPressed() {
   //Do nothing
}

The Menu Button will only be a problem ifyou inflate a menu from your Activity. Standard behaviour is that nothing happens when you hit the Menu Button as long as you don't tell your Activity to do something.




回答2:


Sometimes you'll want to override the default behaviour, fx if you use views and the user expects onback to navigate between views. Other times something else, it all depends on the application. I'd recommend to consider if you should override default behaviour or not.

Heres another example that can be used for all the buttons:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && (isSomething)) {
        something();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}


来源:https://stackoverflow.com/questions/8501732/does-android-application-development-guideline-allow-disabling-default-menu-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!