I'm using the standard onCreateOptionsMenu, but on my Nexus w/ICS, when I tap the vertical menu button in the upper right corner, the dropdown context menu is 3/4 off the screen. Basically, I only see the first 3-4 letters in each menu items text.
Any ideas? Maybe I didn't get that memo!! I dont want to setup an ActionBar. I'd think by default, this should work fine?!?
Again, its pretty much standard menu code for < 3.0 SDK.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (!isPro()) {
// add menu for ad-free Banner (launches Market)
inflater.inflate(R.menu.menu_pro, menu);
}
inflater.inflate(R.menu.menu, menu);
return true;
}
Using standard menu XML...
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/help"
android:icon="#drawable/ic_menu_help"
android:title="#string/menu_help"/>
<item
android:id="#+id/email"
android:icon="#drawable/email"
android:title="#string/menu_email"/>
I cant really say why its cutting off on the top, but I added this to my manifest.xml.
android:theme="#android:style/Theme.Black"
This basically reverts the style back to 2.x menus and places the vertical "dots" on the bottom right.
I actually prefer this over the default compatibility because I still have my icon menus as opposed to plain text-only dropdown menus.
I'd still like to know why the "default" conversion of my menu is screwed up though if anyone can chime in I'll award the solution to that person! (=
You can try to add this to you manifest:
supports-screens android:anyDensity="true"
Related
I thought I should ask a new question for this, but for some context I was able to get the label in position thanks to the good people at How to get a label in the Android action bar
.
So now that I've got that, I want the user to be able to tap the Administrator button and then change it to a different mode (probably just "Administrator", "User", "Guest" to start with but there may be more in the future).
How can I get a list of radio boxes to appear when the button in the top right is clicked? Ideally I want to be able to define those various modes dynamically from within the Java class so that if a new type gets added to the database it will be automatically picked up.
If anyone could point me in the right direction I'd appreciate it. I have seen a few examples from Googling, but unfortunately none of them involved the sort of customised drawable I'm using - and none of them had dynamically populated radio options either.
Thanks
You probably want to have a menu which contains your different items.
Do something like this to create the menu and inflate your xml:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return true;
}
And then for handling the click events:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.admin:
switchToAdminUI();
return true;
case R.id.guest:
switchToGuestUI();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
And your my_menu.xml could look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_overflow"
android:icon="#drawable/abs_ic_menu_moreoverflow_material"
android:showAsAction="always">
<menu>
<item
android:id="#+id/admin"
android:showAsAction="never"
android:icon="#drawable/ic_admin"
android:title="#string/admin"/>
<item
android:id="#+id/guest"
android:showAsAction="never"
android:icon="#drawable/ic_guest"
android:title="#string/guest"/>
</menu>
</item>
</menu>
You can see the android:showAsAction="always" above, which means that it will always show as an action bar icon, and then you put the sub menu items in there.
Try it out and you can also read more about menus here https://developer.android.com/guide/topics/ui/menus.html
After hours of browsing the internet, I am still having a problem showing a menu on my app.
I have a viewflipper with in it several scrollviews and they have several layouts as well.
The whole app works great, I can swipe from scrollview to scrollview without any problems.
Before I connected a Samsung Galaxy Tab to play with, I was running the app in the emulator. There if I pressed the menu button, the submenu was showing and I was able to run functions on menu item touch.
On the tablet, the menu is not showing anywhere.
Here is my menu file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/KPNsites"
android:icon="#drawable/ic_menu_name"
android:title="KPN Sites"/>
<item
android:id="#+id/VDFsites"
android:icon="#drawable/ic_menu_name"
android:title="Vodafone sites"/>
</menu>
In my activity I have this code:
#Override
public boolean onCreateOptionsMenu(Menu my_menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, my_menu);
return super.onCreateOptionsMenu(my_menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.KPNsites:
getKPNsiteInfo();
return true;
case R.id.VDFsites:
getVodafoneSiteInfo();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
When I run the app on the tablet, I only have a small bar at the top with only te app-name in it. I suspect the menu should be visible on that bar?
What else should I do / have done (differently)??
rg,
Eric
If your tablet is running Android 3.0 or greater you should change targetSdkVersion to <= 10 in manifest file.
You may want to consider using ActionBarSherlock this will give your app uniform and modern look on any Android version.
Try this example:
Menu Example
well gave it up for now.
every try messes up what I already got.
To get by, I've put buttons on the layout.
May be with the next project I get it working.
(but then by starting with it before I have all my layouts finished)
Thanks for the help!
rg,
Eric
I am trying to implement ActionBarSherlock in my application and I need to show the menu at the top of my application, integrated in action bar. The problem is that it's not working properly. I am using it like this :
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Refresh")
.setIcon(R.drawable.ic_action_refresh)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add("Settings")
.setIcon(R.drawable.ic_action_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
So the thing which I want to achieve is to show at the right side of my action bar a refresh icon and a menu icon, which should open the default menus when clicked. I checked ForcedOverflowItem example in ActionbarSherlock Demos, but it's not working as I want. I need to look the same as in Android 2.+ and in Android 4.+.
Any advices / helps / suggestions how can I get this to work?
You can do an xml file line this.
I saw this in some other post but I cannot track it rigth now.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/more"
android:showAsAction="always"
android:icon="#drawable/abs__ic_menu_moreoverflow_holo_dark">
<menu>
<item
android:id="#+id/remove"
android:showAsAction="withText|never"
android:title="#string/remove">
</item>
</menu>
</item>
</menu>
Then just inflate it like a normal menu.
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.overlow, menu);
return true;
}
From what I read in ActionbarSherlock's documentation you cannot force the menu icon to appear in Android 4.+. When the device has a menu button the menu icon does not appear. I guess the guy who wrote ActionbarSherlock knows the subject matter well ;-)
Please read the dorjeduck's answer. If you want have same experience on all devices you have to add custom menu with his submenus. Here this the code sumple:
SubMenu sub = menu.addSubMenu("More");
sub.setIcon(R.drawable.abs__ic_menu_moreoverflow_holo_dark);
sub.add(0, MENU_SETTINGS, 0, "Settings");
I followed this tutorial to create a menu
but my menu looks differently:
How can I create a menu with images?
This is my code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/preferences"
android:icon="#drawable/preferences"
android:title="Preferences" />
<item android:id="#+id/help"
android:title="Help"
android:icon="#drawable/ic_action_search" />
</menu>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
/*menu.add(Menu.NONE, PREF_ID, Menu.NONE, "Preferences")
.setIcon(R.drawable.preferences).setAlphabeticShortcut('e');
return (super.onCreateOptionsMenu(menu));*/
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_ygo_main, menu);
return true;
}
First of all I want to say : Say Goodbye to the Menu Button
Your code have no problem, and it should be showing the icons if the drawables are there in correct folder,Working fine on Android 2.2.
The Menu features says :
1. Context menus: Do not support item shortcuts and item icons.
2. Options menus: The icon menus do not support item check marks and only show the item's condensed title. The expanded menus (only available if six or more menu items are visible, reached via the 'More' item in the icon menu) do not show item icons, and item check marks are discouraged.
3. Sub menus: Do not support item icons, or nested sub menus.
No problem with your code, Problem may be with the API level you are using, but still want to suggest that don't use Menu anymore.
Android no longer requires a dedicated Menu button, some devices don’t have one, and you should migrate away from using it.
If you use some following attribute in manifest file then it's will be show your icon....
<activity android:name=".ui.CategoryActivity"
android:label="#string/app_name"
**android:theme="#android:style/Theme.NoTitleBar"**></activity>
It's work fine for me...:)
**must be enter.
I am developing Android 2.1 API 7 project. In order to implement action bar, I use the ActionbarSherlock library.
I have successfully used the sherlock library in my project, the problem is that there is always the default text showing on the sherlock action bar which is my project name.
Even I have used menu layout file (res/menu/action_menu.xml):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test"
android:title="#string/my_test"
android:showAsAction="ifRoom"/>
</menu>
I also inflate above layout in my Activity onCreateOptionsMenu(Menu) method:
public class MyActivity extends FragmentActivity{
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
return true;
}
}
But on the sherlock action bar, the (by default) project name and a android icon are still showing, and it shows on the left side of my custom menu layout item.
So, how to remove the sherlock library default layout and text(project name)??
getSupportActionBar().setDisplayShowHomeEnabled(false)
getSupportActionBar().setDisplayShowTitleEnabled(false)
The API is exactly that of the native ActionBar for future reference.
Instead of adding two lines, replacing the default logo by change the "icon.png" "header_logo.png" in drawable