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>
Related
I am working on my application, but I ran into an error. I have uploaded all the pictures into the drawable folder.
Error:(3) error: not well-formed (invalid token).
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Profile"android:title="Profile" android:icon="#drawable/ic_person_black_24dp" />
<item android:id="#+id/TradingHistory"android:title="TradingHistory" android:icon="#drawable/ic_history_black_24dp" />
<item android:id="#+id/News"android:title="News" android:icon="#drawable/ic_view_list_black_24dp" />
</menu>
What does it mean and how can I solve it?
The error means that the 3rd line is not well-formed: you need a (blank space) between android:id value and android:title key.
This is the correct XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Profile" android:title="Profile" android:icon="#drawable/ic_person_black_24dp" />
<item android:id="#+id/TradingHistory" android:title="TradingHistory" android:icon="#drawable/ic_history_black_24dp" />
<item android:id="#+id/News" android:title="News" android:icon="#drawable/ic_view_list_black_24dp" />
</menu>
Go to code in the toolbar and click on reformat code.
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>
android studio show me: element selector must be declared,why?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/rd_btn_press"
android:state_pressed="true" />
<item android:drawable="#drawable/rd_btn"
android:state_focused="true" />
<item android:drawable="#drawable/rd_btn" />
</selector>
Make sure you have this file in the res/drawable folder. It seems to me that you have it in some other folder in android project. Please comment if that's not the case.
I wanted to create a simple menu for an app. Here is the XML code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item android:id="#+id/new_game"
android:icon="#drawable/magnify"
android:title="New Game"
android:showAsAction="ifRoom"
android:layout_height="wrap_content"/>
<item android:id="#+id/help"
android:icon="#drawable/magnify"
android:title="Help" />
</menu>
But when I click on the design Tab, it gives an error saying that
"Rendering Problems
The following classes cannot be found
-item(Fix build path, Edit in XML)
-menu(Fix build path, Edit in XML)"
What should I do?
Thanks in advance
It looks you have some attributes in your menu that aren't valid - they're layout attributes, not menu attributes.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/magnify"
android:title="New Game"
android:showAsAction="ifRoom"
/>
<item android:id="#+id/help"
android:icon="#drawable/magnify"
android:title="Help"
android:showAsAction="ifRoom"
/>
</menu>
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>