这样一段代码:
public boolean onCreateOptionsMenu(Menu menu){
menu.add(0,Menu.FIRST,0,"开始");
return true;}
我很奇怪,我查了android的官方说明,说Menu是个接口,按道理来说应该是我们只能去实例化实现接口的具体累,为什么这里就直接实例化Menu。另外Menu的add方法是抽象方法,没有具体的实现,这里怎么就直接使用了呢
分不多,谢谢了啊
public boolean onCreateOptionsMenu(Menu menu){
menu.add(0,Menu.FIRST,0,"开始");
return true;}
我很奇怪,我查了android的官方说明,说Menu是个接口,按道理来说应该是我们只能去实例化实现接口的具体累,为什么这里就直接实例化Menu。另外Menu的add方法是抽象方法,没有具体的实现,这里怎么就直接使用了呢
分不多,谢谢了啊
* Interface for managing the items in a menu.
* <p>
* By default, every Activity supports an options menu of actions or options.
* You can add items to this menu and handle clicks on your additions. The
* easiest way of adding menu items is inflating an XML file into the
* {@link Menu} via {@link MenuInflater}. The easiest way of attaching code to
* clicks is via {@link Activity#onOptionsItemSelected(MenuItem)} and
* {@link Activity#onContextItemSelected(MenuItem)}.
* <p>
* Different menu types support different features:
* <ol>
* <li><b>Context menus</b>: Do not support item shortcuts and item icons.
* <li><b>Options menus</b>: The <b>icon menus</b> do not support item check
* s and only show the item's
* {@link MenuItem#setTitleCondensed(CharSequence) condensed title}. The
* <b>expanded menus</b> (only available if six or more menu items are visible,
* reached via the 'More' item in the icon menu) do not show item icons, and
* item check s are discouraged.
* <li><b>Sub menus</b>: Do not support item icons, or nested sub menus.
* </ol>
*/
public interface Menu { /**
* This is the part of an order integer that the user can provide.
* @hide
*/
这里也没有实例化Menu类,里面的“menu.add”说明传进来的参数menu肯定是已经实例化过的具体类的对象。