0

My overflow menu is not appearing in my action bar/App bar (even running emulator) but it only appears in menu_main.xml. What can I do?


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mo.thesis">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

app_bar.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar     xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#ccc">


</android.support.v7.widget.Toolbar>

MainActivity.java

package com.mo.thesis;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
 import android.support.v7.widget.Toolbar;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.widget.Toast;

 public class MainActivity extends ActionBarActivity {

  private Toolbar toolbar;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);


      toolbar = (Toolbar) findViewById(R.id.app_bar);
      setSupportActionBar(toolbar);

  }


  protected boolean onCreateOptionMenu(Menu menu) {

      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;

  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.

      int id = item.getItemId();

      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }

      return super.onOptionsItemSelected(item);
  }


 }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.mo.thesis.MainActivity">

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="78dp"
    android:layout_marginTop="119dp" />


</RelativeLayout>

activity_main.xml Screen Preview:

activity_main.xml

menu_main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">


   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never" />
  </menu>

menu_main.xml Screen Preview: menu_main.xml Android Preview

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
    </style>



</resources>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
M. M. Human
  • 118
  • 2
  • 3
  • 14

2 Answers2

0

Hope this helps, From your code did not found any issue.

There might be other issue ---

The on-screen overflow menu button only appears in the action bar on devices that lack an off-screen MENU button. Try pressing the MENU button on your device or emulator.

please read this Menu Button - Missing answer.

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • Hi there, sorry for the late reply. Nope not yet because base on the tutorial I am following......He has the overflow menu and we are using the same emulator device and same API – M. M. Human Feb 21 '16 at 08:37
-1

Your menu is set to never show

 <item
      android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:orderInCategory="100"
      app:showAsAction="never" />

Change last line there to "always"

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245