开发者

How to show menu button on Android 3.0?

开发者 https://www.devze.com 2023-02-27 08:00 出处:网络
Currently, 开发者_运维技巧I use the phone\'s menu button to trigger a custom event.On Android 3.0 on the XOOM tablet the menu button does not show. How can I make the button available?I believe you ju

Currently, 开发者_运维技巧I use the phone's menu button to trigger a custom event. On Android 3.0 on the XOOM tablet the menu button does not show. How can I make the button available?


I believe you just don't target Honeycomb. I.e., 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 the soft menu button will appear.

You should be asking yourself why you want this functionality on a tablet, though.


You can also detect whether the MENU button is present with this:

ViewConfiguration.get(context).hasPermanentMenuKey()

And if not, you can show a custom menu button in your UI.


In your res folder make sure you have a "menu" folder.. inside that folder you will need menu.xml file..... the xml file should contain information that looks similar to this:

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

You can change out the item section to reflect your own menu.

Make sure you have the xml file saved...

Then go into your main code and do the following:

    public boolean onCreateOptionsMenu(Menu menu){

    MenuInflater inflater = getMenuInflater();

    inflater.inflate(R.menu.menu, menu);

    return true;

    }



}

that's how I do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消