Android options menu - one menu item in one line

I am trying to use the options menu for my application. When I add 2 MenuItem, it appears on one line, but I only need one item on the line and the other on the next line. Please help me.

Thanks..

+4
source share
3 answers

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> 
+1
source

You can not. Android controls how the options menu is laid out, and there are no options to achieve what you want. You will need to create your own view, and then slide it up / down when you press the menu button.

+3
source

I'm not sure if this is possible, but try MenuInflater and the menu resource file .

In the menu resource file, try inserting each element into a separate <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> 

Perhaps this will make the inflatable element display objects in 2 separate lines, sorry, I do not have time to check it. If it does not work, replace the submenu with <group> elements and retest.

+1
source

Source: https://habr.com/ru/post/1346687/


All Articles