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.
Related
I have a sidemenu bar in Codename One implemented using this, I'm considering the switch to the newer Toolbar API but both seems to be one and the same.
I'd like to customize the width to which the side menu bar opens, this is somewhat opaque within the UI and there are no setters I can see since the API consists of addCommand(new Command("My Command");
This blog post mentioned a lot of options but didn't mention the width.
The manual covers some theme constants that allow you to customize the side menu. Specifically:
sideMenuSizeTabPortraitInt The size of the side menu when expanded in a tablet in portrait mode
sideMenuSizePortraitInt The size of the side menu when expanded in a phone in portrait mode
sideMenuSizeTabLandscapeInt The size of the side menu when expanded in a tablet in landscape mode
sideMenuSizeLandscapeInt The size of the side menu when expanded in a phone in landscape mode
You can set these by opening the designer tool, selecting the theme and selecting the "Constants" tab where you can just add anyt one of those.
All of these sizes are in screen percentages.
I want to change the ActionBarSherlock color permanently, I tried the following code but, when I reopen the application it resets to the previous color
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
My intentions are to make a theme that changes the ActionBarSherlock color with user input
First of all, stop using ActionBarSherlock. Use the AppCompat library provided by Android.
Secondly use ActionBar Style Generator to apply style (color) to the ActionBar
I'm implementing NavigationDrawer with ActionBarSherlock and now I'm trying to implement custom icon for opening and closing the drawer. I already set my own icon (white) but I'm not able to get rid of that grey default icon.
in onCreateOptionsMenu I'm doing this:
getSupportActionBar().setDisplayShowTitleEnabled(false); // does not display activity title
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.actionbar_background)); // blue background
getSupportActionBar().setIcon(R.drawable.side_menu_button); // white icon
The picture shows difference when navigation drawer is closed (first) and open (second picture).
Is there any way to do it programmatically? Or is there even some way to do it? I hope it is.
Thank you.
EDIT: This is what I'm trying to achieve:
What you are currently doing is setting the icon on the ActionBar, which is different from setting the icon of the ActionBarDrawerToggle, which is what you want to be dealing with. If you look at the documentation (http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html) and find the constructor, you'll see there's a place to specify a custom Drawable to be used by the toggle.
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.
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.