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.
Related
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.
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.
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.
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>
I am working with the Android 3.0.
I have in the action bar 3 items and one of them is the menu of the application, it also has sub-menu in it.
I want to change the order of the icons so the menu won't be in the right place, I want it to be between the two other items. I tried to change the order in the xml with no success.
Does anyone has an idea how to set the order?
Try setting android:menuCategory and android:orderInCategory for your menu items to set the ordering.
Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/launch_search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_programs"
android:menuCategory="container"
android:orderInCategory="2"
android:showAsAction="always" />
<item android:id="#+id/preferences_screen"
android:icon="#android:drawable/ic_menu_preferences"
android:title="#string/preferences" />
<item android:id="#+id/refresh"
android:icon="#drawable/ic_menu_refresh"
android:menuCategory="container"
android:orderInCategory="1"
android:title="#string/refresh_items"
android:showAsAction="ifRoom" />
</menu>
It will have the same effect as declaring launch_search -action as last, but this way you'll have your actions in the right order for 2.x and older devices while being able to control action ordering for 3.x -devices.
The menu will always go to the right, you cannot control its placement.