0

Hello guys I am really frustrated this is what I want to get

but I what ever I do I cannot get my icon bonded to my Options Menu. I have tried

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    menu.add(1, 1, 0, "Blu-Ray").setIcon(R.drawable.ic_launcher);
     menu.add(1, 2, 1, "DVD").setIcon(R.drawable.ic_launcher);
     menu.add(1, 3, 2, "Hard Disk").setIcon(R.drawable.ic_launcher);
     menu.add(1, 4, 3, "Sites").setIcon(R.drawable.ic_launcher);
     menu.add(1, 5, 4, "USB").setIcon(R.drawable.ic_launcher);
 return true;
}

but with no luck

I then tried to go to my menu then main.xml and did

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

<item
    android:id="@+id/action_settings"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="never"
    android:title="Lolly"/>

And in my Class I did

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
Mohsen Safari
  • 6,669
  • 5
  • 42
  • 58
  • You were doing so well until you got to the last paragraph. It comes across all aggressive and shouty. – Simon Apr 16 '13 at 20:08
  • is it my fault that when ever I post a question some one always has too post the same answer that I got that didnt work? Sorry if it was though I just needed to make a point – user2283550 Apr 17 '13 at 15:59

1 Answers1

2

Cannot Display Icon In The Options Menu

Note that there is no more "options menu" as of Android 3.0. There is the action bar overflow. "Options menu" is still used in some method names (e.g., onCreateOptionsMenu()) for backwards compatibility, but the "options menu" itself is an Android 1.x/2.x construct.

Hello guys I am really frustrated this is what I want to get

That is not an options menu, nor the action bar overflow. It is some UI that the developer of that app created independently.

but I what ever I do I cannot get my icon bonded to my Options Menu

The action bar overflow does not have icons. The old options menu had icons, but with a different rendering than is depicted in your screenshot.

I would like to achieve the layout as above

You are welcome to create some UI for this yourself. Or, you can stick to the standard action bar/options menu approach, so that your application will behave consistently with the other applications on the users' devices.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But I have clearly seen this type of thing work on the the Android UI itself and even on this other picture I managed to get http://imgur.com/NZVAgRs there must be a way around it should it? – user2283550 Apr 17 '13 at 16:04
  • @user2283550: "But I have clearly seen this type of thing work on the the Android UI itself" -- you are welcome to provide proof of your claims. "even on this other picture I managed to get" -- once again, that is some UI that the developer of the app created independently. "there must be a way around it should it?" -- You are welcome to create some UI for this yourself. Or, you can stick to the standard action bar/options menu approach, so that your application will behave consistently with the other applications on the users' devices. – CommonsWare Apr 17 '13 at 16:22
  • thanks for yours answer but it still doesnt answer my question as I have the source code of this project and I still can not find the code that shows the image – user2283550 Apr 17 '13 at 17:41
  • Hi @CommonsWare ... as a new Android tooter I was asking that question over here: http://stackoverflow.com/questions/23710375 Just so I understand you correctly, quite simply, is it the case that there is now (2014) NO "automatic" generation of such a menu (as seen in my six images there)? So TBC if (for some reason) I wanted to have a menu that looked exactly like that -- appearing from the bottom and so on -- indeed I'd simply make it "by hand" in xml ... am I on the right track? Cheers – Fattie May 17 '14 at 15:05
  • @JoeBlow: "Just so I understand you correctly, quite simply, is it the case that there is now (2014) NO "automatic" generation of such a menu (as seen in my six images there)?" -- that's the action bar overflow. It will rise from the bottom of the screen on devices with a MENU button, when the user presses the MENU button. If the user presses a "..." button in the action bar, the overflow drops down from that "...". None of this is the old Android 1.x/2.x options menu. – CommonsWare May 17 '14 at 15:10
  • OK. So if I implement an action bar (say, 10 items) so there's an overflow (say, 7 items on some device). TBC you're saying the "..." will produce a drop down with the 7 items, AND INDEED, the MENU button would produce a popup (as in my images) with the **SAME** seven items? Sorry, I want to do Android Perfection here, and it's actually tricky to just find an app with the behaviour in question. Thanks. – Fattie May 17 '14 at 15:17
  • {TBC I've noticed a number of apps seem to treat the MENU button as a "preferences" feel; it brings up a menu of preference-like things. TBC this is "bad", it's NOT google's recommended emotional direction?} I'm sure this is priceless for other iOS-turned-Android workers BTW. – Fattie May 17 '14 at 15:19
  • @JoeBlow: Yes, bearing in mind that for pre-4.4 devices, the "..." is only there if there is no MENU button. Google is finally killing off the MENU button for good, so devices that ship with 4.4+ should not have one, and the overflow will always be from the "...". But, yes, your seven items will appear in the overflow, whether that overflow drops down from "..." or rises from the bottom on MENU. Any app with an overflow will behave this way. – CommonsWare May 17 '14 at 15:19
  • @JoeBlow: With respect to "emotional direction", I am not quite certain what that means. You may wish to read the design guide section on [the action bar](http://developer.android.com/design/patterns/actionbar.html). – CommonsWare May 17 '14 at 15:20
  • "Google is finally killing off the MENU button for good" TBC in that sentence by MENUButton you do mean the "plastic" physical button? But .. you mean, Google will ask Samsung to stop having such a button? I am 100% >4.4; no baggage or history here. :) – Fattie May 17 '14 at 15:20
  • Is it the case that one "should not" (under Google's recommendations) use the plastic MENU button for "some preference items"? I've noticed that seems to be common BUT I tried hard to read all the Google dock (as as the link) and don't really get it. Am I correct that "many developers ignore that, and continue to use the MENU plastic button for preference-like items? THANKS on behalf all new Android users – Fattie May 17 '14 at 15:22
  • @JoeBlow: "you mean, Google will ask Samsung to stop having such a button?" -- it is now officially against the rules in the Compatibility Definition Document that governs the behavior of Android devices with Google's proprietary apps (e.g., Play Store). "you do mean the "plastic" physical button?" -- I mean a MENU button that is not part of the rendered UI. This can be a capacitive button (see most Samsung devices), a mechanical button, or whatever. – CommonsWare May 17 '14 at 15:23
  • I completely understand everything you say. Excellent. Thanks again, outstanding. If you ever want to know what colour to make buttons on iOS ask me :) – Fattie May 17 '14 at 15:23
  • @JoeBlow: I have no idea what "some preference items" means. What you put in the action bar is up to you. What of that winds up in the overflow is partly up to you and partly up to the action bar implementation, taking into account screen size. Some developers have been using "the plastic MENU button" for things other than the overflow, against recommendations. Those developers are now screwed. – CommonsWare May 17 '14 at 15:24
  • "Some developers have been using "the plastic MENU button" for things other than the overflow, against recommendations..." ah, that's exactly what I was getting at. {It seems to me there are many examples of this: I observed that many tend to put "preferences" in there; just click on say Samsung's phone app for an example. Caveat, I know little about Android and only bought a couple dozen devices the other day.} "Those developers are now screwed." .. right, I completely understand. TBC the apparent persistence of companies doing what (you have now confirmed) is "wrong", confused me greatly. – Fattie May 17 '14 at 15:29