3

i need to add facebook like at setting menu as below image .so how to add new item to setting menu I tried to solve this issue only i had found the setting menu at res > values >string.xml > settings menu .

enter image description here

<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"/>

<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>

egydeveloper
  • 585
  • 5
  • 7
  • 27

1 Answers1

8
  1. Open '/res/menu/menu.xml'
  2. Add this code in it:

    <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"/>
    

  3. Open '/src/(packagename)/(acitivityname).java'

  4. Add this code there
@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);
    }
}
The Badak
  • 2,010
  • 2
  • 16
  • 28