我只是将菜单应用于我的应用程序。
为此,我在 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>
我开始在线出错:
<item android:id="@+id/menu_search"
android:icon="@drawable/icon_search"
android:title="Search" />
错误陈述:
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
编辑:(完整代码)
<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>