1

我正在做菜单项。但我无法在屏幕上查看菜单项。查看菜单项需要做什么。我的代码:

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

7 回答 7

1

我也有这个问题......在我的情况下,这是因为图像保存在文件夹“ drawable”中。我把它们移到了“ drawable-hdpi”那一个,问题就解决了!干杯。

于 2013-01-11T17:12:20.110 回答
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;
}
于 2013-01-11T17:13:01.267 回答
0

缺少菜单充气机:

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

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

于 2013-01-11T17:12:24.567 回答
0

Android Developers上有一个关于Menus的很好的参考资料。

于 2013-01-11T17:12:49.693 回答
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);;
}
于 2013-01-11T17:12:54.030 回答
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/

于 2013-01-11T17:14:15.373 回答
0

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

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

于 2015-07-31T01:27:59.793 回答