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>
Related
I am getting an unknown class error while creating a menu layout.XMl in android studio. Might someone please help me to solve this issues?
The compiler does not recognize the attribute "item".
<item android:id=”#+id/about”
android:title=”About” />
<item android:id=”#+id/help”
android:title=”Help” />
You need to add a menu before them and put in this directory res/menu/
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/about"
android:icon="#drawable/ic_about"
android:title="about" />
<item android:id="#+id/help"
android:icon="#drawable/ic_ help"
android:title="help"/>
</menu>
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.
I'm new in Android
when i set icon in drawer_menu.xml code then after when i open the
navigation drawer menu it open slowly why?
If any one have answer to this question or ever faced this type of
issues then plz reply to this question.
Here is my drawer_menu.xml code.
<?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/home_id"
android:icon="#drawable/home"
android:title="Home"></item>
<item
android:id="#+id/id_setting"
android:icon="#drawable/setting"
android:title="Settings"></item>
</group>
<item android:title="Others">
<menu>
<item
android:id="#+id/notifications"
android:icon="#drawable/noti"
android:title="Notifications"></item>
<item
android:id="#+id/about_us"
android:icon="#drawable/aboutus"
android:title="About us"></item>
</menu>
</item>
</menu>
What is the size of icon?
use 300*300
I am using Navigation Drawer menu without the header. The first item in the menu is too close to the top bar. How can I create margin for the first item? I am using this drawer menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
The outcome is this:
What I did as a workaround is to wrap the first item in a item menu with a blank title ... like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="">
<menu>
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
</menu>
</item>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
And then the outcome is exactly what I wanted:
Can someone please confirm if this workaround is the only way or is there any correct way of achieving the desired output.
Bit late, but any solution?
I've just played around in the xml:
<android.support.design.widget.NavigationView>
...
android:layout_marginTop="?attr/actionBarSize"
android:paddingTop="somePaddingValueInSp"
...
/>
I am working with Android 3.0.
I am trying to build a custom menu in the action bar that has sub-menus in it.
Anybody has the XML hierarchy that should be written?
<item> elements can contain <menu> elements. I've only tested this on ICS but it looks like it should work on Honeycomb as well.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_dropdown"
android:title="More"
android:showAsAction="always">
<menu>
<item android:id="#+id/menu_one" android:title="One" />
<item android:id="#+id/menu_two" android:title="Two" />
</menu>
</item>
</menu>