How to show menu button on Android 3.0?

I am currently using the phone's menu button to trigger a custom event. In Android 3.0 on the XOOM tablet, the menu button is not displayed. How can I make a button available?

+6
source share
3 answers

I believe that you are simply not targeting Honeycomb. Ie, android: targetSdkVersion = "X", where X is less than 11 (and android: minSdkVersion too!)

This will cause your application to be considered a phone application and a soft menu button will appear.

You should ask yourself why you want this functionality on a tablet.

+4
source

You can also determine if the MENU button is present in it:

ViewConfiguration.get(context).hasPermanentMenuKey() 

And if not, you can show the custom menu button in your interface.

+3
source

In the res folder, make sure you have the "menu" folder .. inside this folder you need the menu.xml file ..... The XML file should contain information that looks something like this:

 <menu xmlns:android="https://schemas.android.com/apk/res/android" xmlns:android1="http://schemas.android.com/apk/res/android"> 

You can change the section section to display your own menu.

Make sure you save the xml file ...

Then go to your main code and follow these steps:

  public boolean onCreateOptionsMenu(Menu menu){ MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } } 

how am i doing this.

-1
source

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


All Articles