Android: Menu group in group doesn't work with android:visible? - android

I want to create a Menu, with checkable item and normal item in a group, which can be toggled (show/hide) under different conditions.
but i found that checkable item can only be defined in a group, so i made a menu xml as follow:
Resource Code
<group android:id="#+id/adminMenu"
android:visible="false">
<group android:checkableBehavior="all">
<item android:id="#+id/toggleConsole"
android:title="Console Mode"/>
</group>
<item android:id="#+id/restartApp"
android:title="Restart Game"/>
</group>
What i expected:
But the problem is: The outer group still shows even if defined the property visible = false.
is it a bug or it's not even allowed (or not a best practice) by using encapsulated group?

Group cannot reside inside a group. You should just use a checkable item (don't know why you didn't):
<group android:id="#+id/adminMenu"
android:visible="true">
<item android:id="#+id/toggleConsole"
android:checkable="true"
android:title="Console Mode"/>
<item android:id="#+id/restartApp"
android:title="Restart Game"/>
</group>

Related

Android Menu item Customization

I have an Xamarin android menu ui code as follows
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:checkableBehavior="single">
<item
android:id="#+id/sync_now"
android:checked="false"
android:icon="#drawable/ic_logo"
android:title="Sync Now"/>
</group>
</menu>
I am trying to get a split view on this hazard icon along with the transactions count displayed on the right side of the menu group items shown in the image below but am having no luck.
can someone please tell me how i can do this?
I achieved the above ui by creating a different layout file for everything after sync and added it to the item tag as:
<item
android:id="#+id/sync_now"
android:checked="false"
android:icon="#drawable/ic_syncNow"
android:title="Sync Now"
app:actionLayout="#layout/syncNowCounter"/>
make sure you use app:actionLayout instead of android:actionLayout or it will not work.

Android show sub menu expanded by default

I want to have a PopupMenu with items that have a header. It seemed like the way to achieve this was using a submenu. But the problem is the top level menu shows up collapsed by default. Only after clicking the top item, the sub menu shows. I want to show New Menu expanded and showing all three options instead of requiring me to click on New menu first to reveal the 3 options.
<item android:title="New menu">
<menu>
<item
android:id="#+id/group_item_one"
android:title="Item one"
/>
<item
android:id="#+id/group_item_two"
android:title="Item two" />
<item
android:id="#+id/group_item_three"
android:title="Item three" />
</menu>
</item>
try to add the attribute showAsAction="always"to the items.

Update font style for Android MenuItem

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.

Android: Pop up Menu on Menu button pressed

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.

Android option menu - one menu item in a single row

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.

Categories

Resources