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

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);

Related

Can't add Menu item next to another

I am trying to add Menu item(action_collapse_expand) next to another menu item. Problem is that item is added to expandable list(three dots icon), but not as separate icon. I've just started learning Android and I would like to know what am I doing wrong.
<?xml version="1.0" encoding="utf-8" ?>
<!--For all properties see: http://developer.android.com/guide/topics/resources/menu-resource.html-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_collapse_expand"
android:icon="#drawable/drag_drop"
android:title="Collapse"
android:showAsAction="always|withText" />
<item android:id="#+id/add" android:showAsAction="never" android:title="add" android:icon="#drawable/Add">
<menu>
<item android:id="#+id/map" android:showAsAction="always|withText" android:title="map" android:icon="#drawable/Map" />
<item android:id="#+id/mapK" android:showAsAction="always|withText" android:title=mapK" android:icon="#drawable/MapK" />
</menu>
</item>
<item android:id="#+id/exit" android:showAsAction="always" android:title="Exit" android:icon="#drawable/Close" />
</menu>
Try replacing android:showAsAction with app:showAsAction.
Don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" under your menu tag.

navigation drawer icons are not displayed

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?

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>

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