`

Menu功能菜单

 
阅读更多

一、OptionsMenu的创建

 

	private final int MENU_ABOUT = Menu.FIRST;
	private final int MENU_EXIT = Menu.FIRST + 1;
	public boolean onCreateOptionsMenu(Menu menu){
		String menuLabels[] = {"关于" , "退出"};
		for( int order = 0 ; order < menuLabels.length ; order++ ){
			menu.add( 0 , Menu.FIRST + order , order, menuLabels[order] );
		}
		return super.onCreateOptionsMenu(menu);
	}

	public boolean onOptionsItemSelected(MenuItem item){
		super.onOptionsItemSelected(item);
		switch(item.getItemId()){
		case MENU_ABOUT:toast(item.getTitle() + "");break;
		case MENU_EXIT:toast(item.getTitle() + "");break;
		}
		return false;
	}
	public void toast(String str) {
		Toast.makeText(Main.this,str,Toast.LENGTH_LONG).show();
	}

 

  • 大小: 14.1 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics