No horizontal line displayed between options menu item - android

I implemented an options menu in my application using menu.xml. And the menu is displayed in two rows. But there is no line separator horizontally between these rows of menuItems. But other applications shows menu items with line separator by default.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/scan"
android:icon="#drawable/scan"
android:title="Scan" />
<item android:id="#+id/imei"
android:icon="#drawable/imei"
android:title="IMEI" />
<item android:id="#+id/serno"
android:icon="#drawable/serno"
android:title="SerialNo" />
<item android:id="#+id/update"
android:icon="#drawable/update"
android:title="Updates" />
<item android:id="#+id/about"
android:icon="#drawable/about"
android:title="About" />
<item android:id="#+id/exit"
android:icon="#drawable/exit"
android:title="Exit" />
</menu>
Am I missing something? Thanks in advance.

Related

How to display menu icons for the menu categories in the Navigation Drawer?

I can easily show icons in the menu for the subitems but what if I wanted to shows icon for the category menu items?
I tried like the code example below but it simply ignores android:icon parameter and displays just text.
First screenshot is what I get and the next one how I would like to get it looking.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<item
android:icon="#drawable/ic_lists"
android:title="#string/lists">
<menu>
<item
android:id="#+id/nav_my_lists"
android:title="#string/my_lists" />
<item
android:id="#+id/nav_list_search"
android:title="#string/search_and_apply" />
<item
android:id="#+id/nav_list_applications"
android:title="#string/applications" />
<item
android:id="#+id/nav_list_banned"
android:title="#string/banned" />
</menu>
</item>
<item
android:icon="#drawable/ic_feedback"
android:title="#string/feedback">
<menu>
<item
android:id="#+id/nav_feedback_from_others"
android:title="#string/from_others" />
<item
android:id="#+id/nav_feedback_to_leave"
android:title="#string/i_need_to_leave" />
<item
android:id="#+id/nav_my_feedback"
android:title="#string/i_have_left" />
<item
android:id="#+id/nav_feedback_info"
android:title="#string/banned" />
</menu>
</item>
<item android:title="#string/logout" />
Question is, if there is menu icon property why it doesn't get displayed for top category menu items?
Use the Below Code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:icon="#drawable/ic_lists"
android:title="#string/lists">
<item
android:id="#+id/nav_my_lists"
android:title="#string/my_lists"
/>
<item
android:id="#+id/nav_list_search"
android:title="#string/search_and_apply" />
<item
android:id="#+id/nav_list_applications"
android:title="#string/applications" />
<item
android:id="#+id/nav_list_banned"
android:title="#string/banned" />
<item
android:icon="#drawable/ic_feedback"
android:title="#string/feedback"/>
<item
android:id="#+id/nav_feedback_from_others"
android:title="#string/from_others" />
<item
android:id="#+id/nav_feedback_to_leave"
android:title="#string/i_need_to_leave" />
<item
android:id="#+id/nav_my_feedback"
android:title="#string/i_have_left" />
<item
android:id="#+id/nav_feedback_info"
android:title="#string/banned" />
</group>

Position the checkable button of a checkable menu item in Android Studio

This is how my menu looks like right now:
As you can see, the checkable buttons for Top 10/Top 25 are below the Text. I want them to be right to the Text, in the same line.
How do I pull that off?
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/menuFree"
android:title="Free Apps" />
<item
android:id="#+id/menuPaid"
android:title="Paid Apps" />
<item
android:id="#+id/menuSongs"
android:title="Songs" />
<group
android:id="#+id/menugroupLimit"
android:checkableBehavior="single">
<item
android:id="#+id/menu10"
android:checked="true"
android:title="Top 10" />
<item
android:id="#+id/menu25"
android:title="Top 25" />
</group>
<item
android:id="#+id/menuRefresh"
android:title="Refresh" />

Remove subsection and from navigation drawer submenu

I want to remove the unwanted space created in submenu.
Is there any possibility I can achieve it from menu.xml class?
Here is my navigation_drawer_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/all"
android:checked="true"
android:icon="#drawable/ic_channels"
android:title="All Channels" />
.......
<item
android:id="#+id/other"
android:icon="#drawable/ic_other"
android:title="Others" />
</group>
<item android:title="">
<menu>
<item
android:id="#+id/setting"
android:icon="#drawable/ic_action_settings"
android:title="Settings" />
<item
android:id="#+id/about"
android:icon="#drawable/ic_about"
android:title="About" />
<item
android:id="#+id/share"
android:icon="#drawable/ic_share"
android:title="Share" />
</menu>
</item>
Thanks.
This is how I implement it. Because you are adding a title to a menu it is not recognizing it is empty.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav1"
android:checked="true"
android:title="Pos 1" />
<item
android:id="#+id/nav2"
android:title="Pos 2" />
</group>
<group
android:id="#+id/menu_two"
android:checkableBehavior="single">
<item
android:id="#+id/pos3"
android:title="Pos 3" />
<item
android:id="#+id/pos4"
android:title="Pos 4" />
</group>
</menu>
First, please read this Ian Lake's (Android Developer Advocate) answer:
NavigationView seeks to match the material design specs for the
navigation drawer which state an 8dp space between content areas.
Generally there are no ways to override NavigationView to
specifically break the specifications.
From: How I can remove the unnecessary top padding of the Navigation view?
As you see this undesired padding is sub header of your section.
To delete it, you would need to delete this
<item android:title=""> and </item>
To do it you need ****merge** all menu elements** () into single group (no subsections).
After changes your code should look like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/all"
android:checked="true"
android:icon="#drawable/ic_channels"
android:title="All Channels" />
.......
<item
android:id="#+id/other"
android:icon="#drawable/ic_other"
android:title="Others" />
<menu>
<item
android:id="#+id/setting"
android:icon="#drawable/ic_action_settings"
android:title="Settings" />
<item
android:id="#+id/about"
android:icon="#drawable/ic_about"
android:title="About" />
<item
android:id="#+id/share"
android:icon="#drawable/ic_share"
android:title="Share" />
<menu>
</group>
Still you can do this: How to create a custom navigation drawer in android
If you have a question, please free to ask
Hope it help
To accomplish this programatically, use the overload:
menu.add(int groupId, int itemId, int order, int titleRes)
(and make sure to provide different groupId's for the different sections)

Optional menu item after a submenu not displayed

I have a strange problem on an ActionBar I am setting up on a ListActivity.
Here is the XML I use to setup my menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:title="#string/search_filter"
android:icon="#drawable/ic_search"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_start_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_end_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_filters"
android:title="#string/filters"
android:icon="#drawable/ic_filter"
android:showAsAction="always|withText">
<menu>
<item
android:id="#+id/menu_ratings"
android:title="#string/ratings"
android:icon="#drawable/ic_star"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_emotions"
android:title="#string/emotions"
android:icon="#drawable/ic_smi2"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_categories"
android:title="#string/categories"
android:icon="#drawable/ic_folder"
android:showAsAction="always|withText" />
</menu>
<item
android:id="#+id/menu_search_order"
android:title="#string/search_order"
android:icon="#drawable/ic_search_order"
android:showAsAction="ifRoom|withText" />
</item>
</menu>
The menu items menu_search, menu_start_date, menu_end_date and the sub-menu menu_filters are working well but impossible to get the menu menu_search_order from the physical menu button (nothing happens when I press the button).
So I did a little test to see if the problem is not coming from the submenu, I changed the code and commented the submenu part:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:title="#string/search_filter"
android:icon="#drawable/ic_search"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_start_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_end_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_filters"
android:title="#string/filters"
android:icon="#drawable/ic_filter"
android:showAsAction="always|withText">
<!-- <menu>
<item
android:id="#+id/menu_ratings"
android:title="#string/ratings"
android:icon="#drawable/ic_star"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_emotions"
android:title="#string/emotions"
android:icon="#drawable/ic_smi2"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_categories"
android:title="#string/categories"
android:icon="#drawable/ic_folder"
android:showAsAction="always|withText" />
</menu> -->
<item
android:id="#+id/menu_search_order"
android:title="#string/search_order"
android:icon="#drawable/ic_search_order"
android:showAsAction="ifRoom|withText" />
</item>
</menu>
After this change, the menu works well and the option is displayed when I push the physical menu button.
So my question is: why is the submenu blocking my last menu to appear in the first case?
Thank you!
I still don't know why the code in my question is not working but I found the trick to finally make it work.
I just moved my optional menu (initially at the bottom) before the submenu in the XML file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:title="#string/search_filter"
android:icon="#drawable/ic_search"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_start_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_end_date"
android:title="#string/date_filter"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_search_order"
android:title="#string/search_order"
android:icon="#drawable/ic_search_order"
android:showAsAction="ifRoom|withText" />
<item
android:id="#+id/menu_filters"
android:title="#string/filters"
android:icon="#drawable/ic_filter"
android:showAsAction="always|withText">
<menu>
<item
android:id="#+id/menu_ratings"
android:title="#string/ratings"
android:icon="#drawable/ic_star"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_emotions"
android:title="#string/emotions"
android:icon="#drawable/ic_smi2"
android:showAsAction="always|withText" />
<item
android:id="#+id/menu_categories"
android:title="#string/categories"
android:icon="#drawable/ic_folder"
android:showAsAction="always|withText" />
</menu>
</item>
</menu>
The order here is not important because this menu is the only one I need to see through the physical menu button.
So after so many tries I found a way how to make those items display everywhere correctly. So the trick is to put all items to group element with some id and also android:checkableBehavior="single" , this is only way I was able to get it to render as defined in xml. If I remove id from first group last two items get merged to previous menu sub items. Quite buggy android menu implementation. It should be reported somewhere, but hopefully someone else will do it.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="#+id/signup_1_identification_group"
android:checkableBehavior="single">
<item
android:id="#+id/dopkkpokadad"
android:title="#string/signup_1_identification" />
</group>
<item
android:id="#+id/kokopj"
android:title="#string/signup_6_nationality">
<menu android:id="#+id/signup_6_nationality_menu">
<group
android:id="#+id/signup_6_nationality_group"
android:checkableBehavior="single">
<item
android:id="#+id/dadceqpovjopeqad"
android:title="Hlavna" />
<item
android:id="#+id/cionno"
android:title="Dalsia" />
<item
android:id="#+id/dkbvyukbadad"
android:title="Materinsky Jazyk" />
</group>
</menu>
</item>
<group
android:id="#+id/signup_last_group"
android:checkableBehavior="single">
<item
android:id="#+id/dafeqpokopqdad"
android:title="#string/signup_7_religion" />
<item
android:id="#+id/dakopefhpoiueqdad"
android:title="#string/signup_8_finalization" />
</group>
</menu>
This is how it is rendered correctly from this xml:
When I remove id from fist group I get back wrong behaviour, last two items gets merged, in some cases they will disappear or other weird stuff happens depending on other layout changes, I believe android menu implementation is just buggy...

How to give background into context menu items

In one of my Android projects, I am creating a context menu from a menu folder inside res. It is as below.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/help"
android:title="Help" />
<item android:id="#+id/keyboard"
android:title="Keyboard" />
<item android:id="#+id/exit"
android:title="Exit" />
</menu>
But I want an image to the background of every item. How can I do this?
Try this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/help"
android:title="Help"
android:icon="#drawable/ic_1/>
<item android:id="#+id/keyboard"
android:title="Keyboard"
android:icon="#drawable/ic_2" />
<item android:id="#+id/exit"
android:title="Exit"
android:icon="#drawable/ic_3/>
</menu>
Use styles in your app. Then you can change a default style of Widget.ListView. Note this also changed a style of dialogs with ListView. More details see in this answer.

Categories

Resources