Reputation: 8626
I was just applying menu to my app.
For that i written following code in xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="@+id/menu_search"
android:icon="@drawable/icon_search"
android:title="Search" />
</menu>
I started getting error on line:
<item android:id="@+id/menu_search"
android:icon="@drawable/icon_search"
android:title="Search" />
Error Statements:
Description Resource Path Location Type
Element type "item" must be followed by either attribute specifications, ">" or "/>". activity_login.xml /MessageReader/res/layout line 6 Android XML Format Problem
error: Error parsing XML: not well-formed (invalid token) activity_login.xml /MessageReader/res/layout line 6 Android AAPT Problem
Edit:(Full Code)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="@+id/menu_search"
android:title="Search" />
</menu>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/msngr"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.38"
android:src="@drawable/logo" />
<TextView
android:id="@+id/view_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/view_username"
/>
<EditText
android:id="@+id/txt_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:background="@android:drawable/editbox_background"
>
<requestFocus />
</EditText>
<TextView
android:id="@+id/view_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/view_password"
/>
<EditText
android:id="@+id/txt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
/>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="@drawable/login"
/>
<TextView
android:id="@+id/link_to_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/link_to_register" />
</LinearLayout>
</ScrollView>
Upvotes: 0
Views: 1943
Reputation: 18933
You need to put your menu XML in separate file (menu.xml) and put that file in /res/menu folder of your project.
And after that you ca use it in
onCreateOptionsMenu(Menu menu) method
Upvotes: 0
Reputation: 75629
You need to put your menu XML in separate file (i.e. menu.xml
) and put that file in /res/menu
folder of your project.
EDIT
but latter how can i have that menu on my login page?
You do not add menu to layout. You add it to i.e. Activity. And you do this in the code that way:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
Upvotes: 2