To show menu icon in action bar as shown in the below image, follow these steps

  1. Create a menu resource inside res/menu, name it whatever you want.
  2. Override onCreateOptionsMenu and inflate it.
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.yourentry, menu);
        return true;
    }
  3. Set android:showAsAction="always in the layout file.
    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/menu_setting"
            android:icon="@drawable/ic_settings_24px"
            android:title="@string/setting_text"
            app:showAsAction="always"/>
    </menu>
  4. If an actions in the ActionBar is selected, the onOptionsItemSelected() method is called. It receives the selected action as parameter. Based on this information you code can decide what to do for example:
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
        case R.id.menuitem1:
          Toast.makeText(this, "Menu Item 1 selected", Toast.LENGTH_SHORT).show();
          break;
        case R.id.menuitem2:
          Toast.makeText(this, "Menu item 2 selected", Toast.LENGTH_SHORT).show();
          break;
      }
      return super.onOptionsItemSelected(item);
    }