navigation drawer icons are not displayed - android

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?

Related

Navigation menu items with dropdown menu Android

I'm using Navigation Drawer. I've used a spinner layout in a menu item, but it looks bad. I'm trying to have a view like this, but IDK how.
So when I press PRODUCT, a dropdown submenu appears.
I've tried this code to do so but it's not working.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group android:checkableBehavior="single"
>
<item
android:id="#+id/nav_home"
android:checkable="true"
android:icon="#drawable/ic_outline_home_24"
android:title="#string/home" />
<item
android:id="#+id/nav_products"
android:checkable="true"
android:visible="true"
android:actionLayout="#android:layout/simple_spinner_dropdown_item"
android:icon="#drawable/ic_outline_shopping_bag_24"
app:showAsAction="collapseActionView"
android:title="#string/products" >
<menu>
<item
android:id="#+id/fire_alam"
android:title="#string/fire_alarms"
android:checkable="true"
app:showAsAction="never"
/>
<item
android:id="#+id/fire_fighting"
android:checkable="true"
app:showAsAction="never"
android:title="#string/fire_fighting"/>
</menu>
</item>
<item
android:id="#+id/nav_serv"
android:checkable="true"
android:icon="#drawable/ic_outline_room_service_24"
android:title="#string/services" />
</group>
</menu>
You can use ExpandableListView
Check:- https://www.journaldev.com/9942/android-expandablelistview-example-tutorial
Also you can use it in NavigationView
Check:-
https://www.journaldev.com/19375/android-expandablelistview-navigationview

Adjust item in navigation drawer to the left if there's no icon

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>

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>

how can i show android:icon in android menu ( android studio)

i create application with default android studio menu, but when i change default icon with my drawable icon this circle icon is not visible.
my problem is how can i show icon in my android menu.
I used this XML:
<?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"
>
<group android:checkableBehavior="single">
<item android:id="#+id/nav_radio" android:icon="#drawable/radio_icon"
android:title="Radio" />
<item android:id="#+id/nav_tv" android:icon="#drawable/tv_icon"
android:title="TV" />
</group>
<item android:title="Autre">
<menu>
<item android:id="#+id/nav_share" android:icon="#drawable/share_icon"
android:title="Share" />
<item android:id="#+id/nav_send" android:icon="#drawable/mail_icon"
android:title="Send" />
<item android:id="#+id/nav_like" android:icon="#drawable/heart_icon"
android:title="Rate Me" />
<item android:id="#+id/nav_recording" android:icon="#drawable/cloud_icon"
android:title="Recording" />
<item android:id="#+id/nav_close" android:icon="#drawable/power_icon"
android:title="Close" />
</menu>
</item>
</menu>
and i don't show icone
please help me
In you activity Where you have used NavigationView use this one line of code. doing this may solve your problem.
setItemIconTintList(null);
in your Activity
mNavigation = (NavigationView) findViewById(R.id.navigation);
mNavigation.setItemIconTintList(null);

android toolbar why do i get options menu instead of icons

so i made my own toolbar with a menu and i am infalting it:
toolbarBottom.inflateMenu (R.menu.user_interaction);
and this is the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res/android">
<item app:title="Edit"
app:id="#+id/post"
app:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item app:id="#+id/menu_share"
app:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
app:title="Undo" />
<item app:id="#+id/test"
app:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
app:title="Redo" />
</menu>
what i get now is the 3 android option dots on the right side of my bar. If i press it my 3 menuĀ“s appear. What i want is the 3 menu items to appear on the bar itself witht he 3 icon drawables.
Where is my mistake? Did i forgot something? :O
ok i solved it like this:
<?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" >
<item android:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
It should be:
<?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">
<item android:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>

Categories

Resources