Android 4.0 detects if user has hardware back / home keys

Is there a way in ICS / HC to detect if a user has access to a hardware menu key?

Depending on the configuration, I hope to change how the action bar populates, for example:

If the user has a physical home button, reduce the number of buttons displayed on the action bar.

Thanks Laurence

+6
source share
2 answers

The time has come, but I found a more reliable way than relying on hasPermanentMenuKey () , which does not work for newer phones like HTC One , which have no menu keys, but you have home and back keys, so no need (or show) soft navigation bar. To work around this, try the following code, which also checks the return button:

boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); if(!hasMenuKey && !hasBackKey) { // Do whatever you need to do, this device has a navigation bar } 
+2
source

both ICS and cellular (unfortunately) replaced the menu key for the combination of the action panel and the system panel, not allowing us to configure when we want to show the menu button.

just don’t assume it exists, or set the target sdk file to 10, which will always display the menu key (which looks like 3 dots).

In any case, it would be interesting if you find a way to check if the menu button exists.

0
source

Source: https://habr.com/ru/post/907993/


All Articles