[英]Add icon to menu item from java code (android 2.3)
Is there a possibility, to add an image to menu item, from java code (not from xml file)? 是否可以通过Java代码(而不是xml文件)将图像添加到菜单项?
For example (in XML): 例如(在XML中):
item android:id="@+id/help"
android:icon="@drawable/ic_help"
android:title="@string/help"
Second line adds a picture (icon) to an item, but this is XML file. 第二行将图片(图标)添加到项目,但这是XML文件。
In code, when I'm making a menu there is only few constructor to add an item For example: public boolean onCreateOptionsMenu(Menu menu){ 在代码中,当我制作菜单时,只有很少的构造函数可添加项目。例如:public boolean onCreateOptionsMenu(Menu menu){
menu.add(0,0,0,"Czerwony");
But anyone with image (only title text/string). 但是任何有图像的人(仅标题文本/字符串)。
menu.add((0,0,0,"Czerwony").setIcon(R.drawable.edit_icon);
另请参阅本文: 如何在Java代码中的Android中创建菜单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.