How can I display a menu in my application when I don't have a hardware menu button on my phone and when I hide the titlebar?
To answer to your question: you can open the menu programmatically using openOptionsMenu().
However, you probably should include a ActionBar instead, as suggested in the comments.
Related
I need help on how I would make an options menu outside of toolbar. The one with the dropdown like the options menu in chrome or messaging, not the contextual which pops up like an alert/progress dialog.
I am planning to use it beside a textview, not on a toolbar. I get the idea of having to create an xml for the menu, but what do I use on the layout and how do I inflate it?
How to add menu button without action bar?
those are two pretty acceptable solutions, doubt there is any other workaround...or just use a spinner
when user select text on android..some buttons will appear,like "copy & paste".
what i'm trying to do is to make my app show a button on the screen when text gets selected on my android phone.
These answers are what you are looking for:
How to add item into popup copy/paste menu on a android selected TextView?
Making custom copy and paste menu appear when text is selected
normally when the menu button is pressed , the menu appears from the center bottom of the screen. Is there a way to make it appear from sides.
On Android 3.0 and higher, items from the options menu are presented by the action bar which is standard way to provide access to menus and normally menus appears from top right corner. You should go through this once:
Menus Action Bar
I want to use android menu function.
And I already set onPrepareOptionsMenu(),
and set the content.
But I have problem, that my pad has no menu icon to click.
Do I need to set anymore?
Since Android 3.0 (Honeycomb), that was made especially for tablets, there is no more hardware menu button (but phones still got one), so to use ActionBar for tablets, You could follow this tutorial:
http://www.dreamincode.net/forums/topic/274639-android-actionbar-tutorial/
and read this too:
http://developer.android.com/guide/topics/ui/actionbar.html
The overflow option menu icon (looks like 3 dots) at top-right corner will not appear if your device has a hardware menu key.
Your device must be at least on 3.x.
In tablet you have implement ActionBar in your activity. For enable and use of ActionBar you must have to use Titlebar for your activity. Just create the Theme in style.xml having Title bar and store in value-xlarge dir for large screen. And get the ActionBar object by using this getActionBar().
Note: You must have to use API 11 or above if you have minSDK below 11 then you have check version of OS
Instead of using
onPrepareOptionsMenu(),
which is for updating text and other thing once menu option is created, use
public boolean onCreateOptionsMenu (Menu menu)
and selection of menuitem can be achieved by
public boolean onOptionsItemSelected (MenuItem item)
Many examples can be found for menu creation,updation and selection.
If you set android:targetSdkVersion bigger than 10 and you are using theme NoTitleBar in the devices which are running Android 3+ and which don't have menu button there won't show a software menu button next to back button. If you want that option to be enabled set your targetSdkVersion to 10 and test i your device if there will show the software menu button.
as the title suggests I'm trying to add code to my app which allows the user to click on an item in the action bar menu which then unfolds a drop down menu (spinner class?) containing a few options such as lamp, tv etc. - each with an icon. The user will then be able to select one of these and drag and drop the icon (or an image representing the icon) to the canvas where it is then drawn. What is the best way to go about this?
If you're referring to the ActionBar overflow menu items, then you would have to take a look at the code for the ActionBar in the framework and extend it in your application, but that would firstly require quite a hassle and secondly would break compatibility when changes are made to the ActionBar in new versions of Android.
Also, this goes completely away from what the ActionBar is intended to be. You should only have actions in the overflow menu, not contain elements that directly interact with the Activity content. It's just wrong. Consider redesigning your UI so that you implement the requested featured inside the content view, not on the ActionBar.