如何在Android设置菜单中添加新项?

egy*_*per 3 android android-intent android-layout

我需要在设置菜单中添加facebook,如下图所示.如何在设置菜单中添加新项目我试图解决此问题只有我在res> values> string.xml>设置菜单中找到了设置菜单.

在此输入图像描述

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<menu>
<item
    android:id="@+id/action_settings"
    android:orderInCategory="1"
    android:showAsAction="never"
    android:title="Settings"/>

<item
    android:id="@+id/action_about"
    android:orderInCategory="2"
    android:showAsAction="never"
    android:title="About"/>
<item
    android:id="@+id/action_exit"
    android:orderInCategory="3"
    android:showAsAction="never"
    android:title="Exit"/>
Run Code Online (Sandbox Code Playgroud)

<TextView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"


 <RelativeLayout   


          android:layout_width="match_parent"
          android:layout_height="match_parent">

     <WebView
         android:id="@+id/web_engine"
         android:layout_width="match_parent"
         android:layout_height="match_parent" >

      </WebView>
Run Code Online (Sandbox Code Playgroud)

The*_*dak 8

  1. 打开'/res/menu/menu.xml'
  2. 在其中添加此代码:

    <item
        android:id="@+id/action_about"
        android:orderInCategory="2"
        android:showAsAction="never"
        android:title="About"/>
    <item
        android:id="@+id/action_exit"
        android:orderInCategory="3"
        android:showAsAction="never"
        android:title="Exit"/>
    
    Run Code Online (Sandbox Code Playgroud)

  3. 打开'/src/(packagename)/(acitivityname).java'

  4. 在那里添加此代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_about:
        // About option clicked.
        return true;
    case R.id.action_exit:
        // Exit option clicked.
        return true;
    case R.id.action_settings:
        // Settings option clicked.
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}
Run Code Online (Sandbox Code Playgroud)