菜单项不可见

时间:2013-01-11 17:05:58

标签: android menu menuitem

我在做菜单项目。但我无法在屏幕上查看菜单项。要查看“菜单”项,需要执行哪些操作。我的代码:

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

7 个答案:

答案 0 :(得分:1)

我也有这个问题......在我的情况下,由于图像保存在文件夹“drawable”中。我把它们移到了“drawable-hdpi”,问题解决了!欢呼声。

答案 1 :(得分:1)

使用此:

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

答案 2 :(得分:0)

缺少菜单Inflater:

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

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

答案 3 :(得分:0)

关于Android DevelopersMenus有很好的参考。

答案 4 :(得分:0)

super.onCreateOptionsMenu(menu)

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

答案 5 :(得分:0)

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

看看这个例子

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

答案 6 :(得分:0)

我的是因为在styles.xml中,父级主题有错误。确保它以android开头:试试这个:

jQuery.fn.extend({
        selectedAsJSON: function(){
            var result = [];
            $('option:selected', this).each(function(){
                result.push($(this).data());
            })
            return result;
        }
    });