I got a problem with the android code. I have a Menu with a SubMenu and I want to set the font style to bold for (Sub)MenuItem if it was clicked by the user. So the menu acts like a filter list, where you can select only one filter at the time and the selected MenuItem become bold. I have to do this programatically, benause the categories were generated/added dynamically.
The menu structure looks like this
...
<menu>
<item android:id="#+id/menu_sort_alphabetically" android:title="by name"></item>
<item android:id="#+id/menu_sort_value" android:title="by value"></item>
<item android:id="#+id/menu_sort_category" android:title="by category">
<menu android:id="#+id/menu_category"
android:checkableBehavior="single">
<item android:title="Category 1"></item>
<item android:title="Category 2"></item>
...
</menu>
</item>
</menu>
...
I tried several ways, but haven't found any solution or idea. It would be nice if someone could help me.
Related
I have this menu layout
<item
android:id="#+id/refresh"
android:icon="#drawable/refresh"
android:title="#string/refresh"/>
<item
android:icon="#drawable/sort_neutral"
android:title="Sort By Date">
<menu>
<item
android:id="#+id/sortNewToOld"
android:icon="#drawable/sort_up"
android:title="Newest To Oldest"/>
<item
android:id="#+id/sortOldToNew"
android:icon="#drawable/sort_down"
android:title="Oldest To Newest"/>
</menu>
</item>
the items "#+id/refresh" and "#drawable/sort_neutral" are shown correctly, but the two icons inside the "android:title="Sort By Date" are not shown, I just can see the title of them. any help would be appreciated.
note
I am using real mobile song ericsson 2.3.1
Your icon are probably too large for the menu. Make sure you are using a correct icon size.
i want to add customs icons to my option menu, like that :
How can i do that with custom icons in my menu.xml ?
Or if you know the list of defaults icons, i am interested by that...
Here is my actual menu.xml code :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_settings"
android:title="#string/menu_settings"
android:orderInCategory="100"
android:showAsAction="never" >
</item>
<item android:id="#+id/item1" android:title="Accueil" android:titleCondensed="Accueil" android:icon="#android:drawable/ic_menu_home"></item>
</menu>
Thanks !
Inside of the item tag, use android:icon="#drawable/your_icon". That should work.
I've implemented a contextual action bar. The menu being loaded and inflated in onCreateActionMode is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:title="#string/call_context_menu_title">
<item android:id="#+id/menu_answer_call"
android:title="#string/answerCall"
android:showAsAction="ifRoom" />
<group android:id="#+id/activeCallContextMenuItems">
<item android:id="#+id/menu_end_call"
android:title="#string/hangupCall"
android:showAsAction="ifRoom"/>
<group android:id="#+id/multipleActiveCallsContextMenuItems">
<item android:id="#+id/menu_transfer_call"
android:title="#string/transferCall"
android:showAsAction="ifRoom"/>
<item android:id="#+id/menu_conference_call"
android:title="#string/conferenceCall"
android:showAsAction="ifRoom"/>
</group>
</group>
</menu>
These items are shown when I click on an item in a ListView. When it is active, besides listing my 4 options, it puts a "Select Action" text before the first menu item. Is there any way to get Android to not show the "Select Action" hint? The menu items have self explanatory text so it is redundant (and even confusing if the hint is being cut off in the middle... e.g. on my S3 it says "Select..." and then I have my menu items)
I want to have a normal menu button pop up a second menu.
I don't want a listview of options to display, I want a second, standard menu to pop up when I press a button on the menu.
Using openOptionsMenu(); works when you use onCreateOptionsMenu
but it does not work when you use: onPrepareOptionsMenu
Since I want to change the options on the menu dynamically, I need to use onPrepareOptionsMenu.
Thanks
Use a menu group for any menu item that doesn't have an action itself but opens up a second menu. Here's an example of one I did.
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:titleCondensed="Cats" android:title="Cats" android:id="#+id/cats">
<menu>
<group android:id="#+id/catsGroup">
<item android:titleCondensed="Lolz Cats" android:title="Lolz Cats" android:id="#+id/twod"></item>
<item android:titleCondensed="Ugly Cats" android:title="Ugly Cats" android:id="#+id/ref"></item>
<item android:titleCondensed="Dumb Cats" android:title="Dumb Cats" android:id="#+id/vr"></item>
</group>
</menu>
</item>
<item android:titleCondensed="Dogs" android:title="Dogs" android:id="#+id/dogs">
<menu>
<group android:id="#+id/dogsGroup">
<item android:titleCondensed="Awesome Dog" android:title="Awesome Dog" android:id="#+id/pan"></item>
<item android:titleCondensed="Under Dog" android:title="Under Dog" android:id="#+id/zoom"></item>
<item android:titleCondensed="Snoopy" android:title="Snoopy" android:id="#+id/contrast"></item>
<item android:titleCondensed="Scooby Doo" android:title="Scooby Doo" android:id="#+id/page"></item>
<item android:titleCondensed="Pluto" android:title="Pluto" android:id="#+id/rotate"></item>
</group>
</menu>
</item>
</menu>
The first menu items that will show are "Cats" and "Dogs". When you select on of these, their sub items will be shown. Hope this helps.
I am trying to use option menus for my application . When I add 2 MenuItem it shown in a single row, but i need only one item in a row and other in next row. Please help me.
Thanks..
You cannot. The Android system handles how the options menu is laid out and there are no options to achieve what you want. You would have to make your own View, and then slide this up/down when the menu button is pressed.
tr this code
<item android:id="#+id/last_most_item"
android:orderInCategory="10"
android:title="#string/last_most_often" />
<item android:id="#+id/middle_most_item"
android:orderInCategory="7"
android:title="#string/middle_most_often" />
<item android:id="#+id/first_most_item"
android:orderInCategory="4"
android:title="#string/first_most_often" />
</group>
I'm not sure it's possible but try with the MenuInflater and a menu resource file.
In your menu resource file, try to embed each item in a separated <menu> element, something like this :
<menu>
<item>
<menu>
<item android:id="#+id/item1"
android:title="#string/item1" />
</menu>
</item>
<item>
<menu>
<item android:id="#+id/item2"
android:title="#string/item2" />
</menu>
</item>
</menu>
Maybe it will force the inflater to show the items in 2 separated lines, sorry I don't have the time to test it. If it's not working, replace the submenus with <group> elements and retest.