Anu0042
Anu0042

Reputation: 253

Menu item not visible

I am doing menu item. But i am not able to view the menu item in the screen. What need to be done to view the Menu item. My code:

            public boolean onCreateOptionMenu(Menu menu){
      super.onCreateOptionsMenu(menu);

       int group1 = 1;
       int group2 = 2;

      MenuItem info = menu.add(group1,1,1,"About");
      info.setIcon(R.drawable.ic_launcher);
      MenuItem set = menu.add(group2,2,2,"App Setting");
      set.setIcon(R.drawable.images);

       return true;
      }


         private boolean MenuChoice(MenuItem item){

            switch(item.getItemId()){
                case 1:
                Toast.makeText(this, "You clicked on item 1",    Toast.LENGTH_LONG).show();
                return true;
        }

       return false;
    }

Upvotes: 1

Views: 876

Answers (7)

timmyt123
timmyt123

Reputation: 75

Mine was because in styles.xml, parent had a wrong theme. Make sure it starts with android: Try this:

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.DeviceDefault.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

Upvotes: 0

Ramesh Sangili
Ramesh Sangili

Reputation: 1633

 @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }

Look at this example

http://www.androidhive.info/2011/09/how-to-create-android-menus/

Upvotes: 0

Payal
Payal

Reputation: 913

Use this :

public boolean onCreateOptionsMenu(Menu menu){
    Log.d(TAG, "CreateMenu");

     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.layout.menu, menu);
       return true;


}



@Override
public boolean onOptionsItemSelected(MenuItem item)
{    

        switch(item.getItemId()) {
                    case R.id.x:

            Toast.makeText(this, "You clicked on item 1",    Toast.LENGTH_LONG)         }
                        break;
                    }


    }
    return true;
}

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

try as after returning super.onCreateOptionsMenu(menu) from onCreateOptionMenu

 public boolean onCreateOptionMenu(Menu menu){

   int group1 = 1;
   int group2 = 2;

   menu.add(group1,1,1,"About").setIcon(R.drawable.ic_launcher);
   menu.add(group2,2,2,"App Setting").setIcon(R.drawable.images);

   return super.onCreateOptionsMenu(menu);;
}

Upvotes: 0

EvZ
EvZ

Reputation: 12169

There is a nice reference on Android Developers about Menus.

Upvotes: 0

Jonathon Cwik
Jonathon Cwik

Reputation: 997

Missing Menu Inflater:

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);

via: http://developer.android.com/guide/topics/ui/menus.html

Upvotes: 0

Dixit Patel
Dixit Patel

Reputation: 3192

I had this problem too... It was due in my case to the fact that the images were saved in the folder "drawable". I moved them to the "drawable-hdpi" one and the problem was solved! Cheers.

Upvotes: 1

Related Questions