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" />
Related
I have a navigation drawer. In the menu, I am trying to use some icons to the items in the menu but they don't appear. it looks like this.
here is the XML for the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_overview"
android:icon="#drawable/ic_bell"
android:title="#string/overview" />
<item
android:id="#+id/nav_symptoms"
android:icon="#drawable/ic_symptoms"
android:title="#string/symptoms" />
<item
android:id="#+id/nav_prevention"
android:icon="#drawable/ic_preventation"
android:title="#string/prevention" />
<item
android:id="#+id/nav_treatment"
android:icon="#drawable/ic_medicine"
android:title="#string/treatment" />
<item
android:id="#+id/nav_statistics"
android:icon="#drawable/ic_statistics"
android:title="#string/statistics" />
<item
android:id="#+id/nav_world"
android:icon="#drawable/ic_world_data"
android:title="World-wide Statistics" />
<item
android:id="#+id/nav_settings"
android:title="#string/settings" />
</group>
</menu>
all the icons that I am using are svgs and I imported them to android studio as vector assests.
what am I doing wrong here?
My current problem is i want to move both my 'Log out' and 'About the app' to the left because both of them doesn't have any icon.
i'm currently finding a way to move the 'log out' and 'about the app' to adjust on the left so that they can be align with the icons.
Here is my navigation drawer menu:
<?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/drawer_home"
android:icon="#drawable/ic_drawer_home"
android:title="Home" />
<item
android:id="#+id/drawer_pay"
android:icon="#drawable/ic_drawer_pay"
android:title="Pay" />
<item
android:id="#+id/drawer_transfer"
android:icon="#drawable/ic_drawer_transfer"
android:title="Transfer" />
<item
android:id="#+id/drawer_load"
android:icon="#drawable/ic_drawer_load"
android:title="Load" />
<item
android:id="#+id/drawer_link"
android:icon="#drawable/ic_balance_card"
android:title="Link ATM Card" />
<item
android:id="#+id/drawer_merchants"
android:icon="#drawable/ic_drawer_merchants"
android:title="Locate Merchants" />
<item
android:id="#+id/drawer_logout"
android:title="Log Out" />
<item
android:id="#+id/drawer_about"
android:title="About the App" />
</group>
</menu>
Separate those sections you want to addjust to the left like below:
<?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/drawer_home"
android:icon="#drawable/ic_drawer_home"
android:title="Home" />
<item
android:id="#+id/drawer_pay"
android:icon="#drawable/ic_drawer_pay"
android:title="Pay" />
<item
android:id="#+id/drawer_transfer"
android:icon="#drawable/ic_drawer_transfer"
android:title="Transfer" />
<item
android:id="#+id/drawer_load"
android:icon="#drawable/ic_drawer_load"
android:title="Load" />
<item
android:id="#+id/drawer_link"
android:icon="#drawable/ic_balance_card"
android:title="Link ATM Card" />
<item
android:id="#+id/drawer_merchants"
android:icon="#drawable/ic_drawer_merchants"
android:title="Locate Merchants" />
</group>
<item android:title="You title">
<menu>
<item
android:id="#+id/drawer_logout"
android:title="Log Out" />
<item
android:id="#+id/drawer_about"
android:title="About the App" />
</menu>
</item>
</menu>
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>
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)
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.