egydeveloper
egydeveloper

Reputation: 585

How to add new item to setting menu at Android?

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>
      
    
      

Upvotes: 3

Views: 25421

Answers (1)

The Badak
The Badak

Reputation: 2030

  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);
    }
}

Upvotes: 8

Related Questions