Toolbar icons are not showing - android

I'm trying to use Toolbar in my app, I was able to follow android tutorial to the point of displaying these items as icons.
My Items shows as a sub menu of "..." on the right but no icon is shows. I tried using android:showAsAction="always" but I keep getting errors about issues with a name space and that I should use res-auto. When I tried that break my inflator of the menu and I was getting some strange title errors even though I had these tags defined.
Is there a way to display some icons on a toolbar and how can I force it with showAsAction=always without throwing errors.
Thank you
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/favorite_ico"
android:icon="#mipmap/ic_launcher"
android:title="Item 1"
android:showAsAction="ifRoom" />
<item
android:id="#+id/settings_ico"
android:title="Item 2" />
</menu>

if you are trying to use showAsAction="always"
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/favorite_ico"
android:icon="#mipmap/ic_launcher"
android:title="Item 1"
app:showAsAction="always" />
<item
android:id="#+id/settings_ico"
android:title="Item 2" />
</menu>
you need to import app not android

Please modify your code to this
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/favorite_ico"
android:icon="#mipmap/ic_launcher"
android:title="Item 1"
app:showAsAction="ifRoom" />
<item
android:id="#+id/settings_ico"
android:title="Item 2" />
</menu>

showAsAction should be from support library. for this purpose you need to use app:showAsAction. this need appNs
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/favorite_ico"
android:icon="#mipmap/ic_launcher"
android:title="Item 1"
app:showAsAction="ifRoom">
</item>
<item android:id="#+id/settings_ico"
android:title="Item 2">
</item>
</menu>

Related

Android How to move menu to the left on small screens

When i added additional item to menu, it go off the screen on phone with smaller screen like 400x800. I tried to add padding but i don't want to make icon smaller but only move whole menu a little bit to the left because i see there is space for that. Does anyone has similar problem and resolve it ?
code:
<?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:id="#+id/graphic"
android:icon="#drawable/ic_graphic_white_30dp"
android:title="Graphic"
app:showAsAction="always" />
<item
android:id="#+id/save"
android:icon="#drawable/ic_save_white_24dp"
android:title="#string/save"
app:showAsAction="always" />
<item
android:id="#+id/share"
android:icon="#drawable/ic_share_white_24dp"
android:title="#string/share"
app:showAsAction="always" />
<item
android:id="#+id/count"
android:icon="#drawable/ic_pie_chart_white_24dp"
android:title="#string/count"
app:showAsAction="always" />
<item
android:id="#+id/camera"
android:icon="#drawable/ic_camera_alt_white_24dp"
android:title="#string/photo"
app:showAsAction="always" />
<item
android:id="#+id/lock"
android:icon="#drawable/ic_action_secure"
android:title="#string/lock"
app:showAsAction="always" />
</menu>
You can use configrations of your actionBar as below:
ActionBar mActionBar = getSupportActionBar();
mActionBar.setNavigationMode(NAVIGATION_MODE_LIST);
mActionBar.setListNavigationCallbacks(mAdapter, mNavigationCallback);
You can follow this example : Sample Here

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.

Error when Adding Menu to App - Xamarin c# Visual Studio

I am trying to inflate an XML Menu inside my App, but i get the following error when I try to Deploy the App on an Emulator:
Unhandled Exception:
Java.Lang.RuntimeException: Unexpected end of document occurred
Also my XML is located in Resources/menu/main
Inflate Menu Code:
XML Code:
<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/mnuAppLogo"
android:title="logoHere"/>
<item android:id="#+id/mnuAppName"
android:title="App Name"/>
<menu>
<item android:id="#+id/submenuHelp"
android:title="Help" />
<item android:id="#+id/submenuExit"
android:title="Exit" />
</menu>
</menu>
Why is this?
Let me know if you need more code...
Thanks in advance.
UPDATE 1:
I want to make the logoHere and App Name appear in spots 1 and 2 with the other 2 Help and Exit inside the Menu.
To create a "submenu", the elements must be included within an item element:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mnuAppLogo" android:title="logoHere" />
<item android:id="#+id/mnuAppName" android:title="App Name">
<menu>
<item android:id="#+id/submenuHelp" android:title="Help" />
<item android:id="#+id/submenuExit" android:title="Exit" />
</menu>
</item>
</menu>
How do I make it so that the First 2 (logoHere and App Name) are not in the "Hamburger Menu" and just on the Action Bar? The Help and Exit however will be inside the Menu.
You can use showAsAction="never" to always place the menu item in the overflow menu and showAsAction="ifRoom" to display it as an action bar button IF there is room for it.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mnuAppLogo" showAsAction="ifRoom" android:title="logoHere" />
<item android:id="#+id/mnuAppName" showAsAction="ifRoom" android:title="App Name" />
<item android:id="#+id/submenuHelp" showAsAction="never" android:title="Help" />
<item android:id="#+id/submenuExit" showAsAction="never" android:title="Exit" />
</menu>

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

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...

Categories

Resources