¾È±Ô °øºÎ¹æ

Android > ActionBar - »ó´Ü¿¡ ¸Þ´º Ãß°¡Çϱâ(Action Bar Menu)

µî·ÏÀÏ : 2017-07-05 19:02 Á¶È¸¼ö : 53,061


 


ÀÌ·¸°Ô ¾Û »ó´ÜÀÇ ¾×¼Ç¹Ù¿¡ ¼³Á¤ ¹öÆ°À» ´©¸£¸é ³ª¿À´Â ¸Þ´º¸¦ ¸¸µé°íÀÚ ÇÑ´Ù.

±²ÀåÈ÷ °£´ÜÇѵ¥, MainActivity¿¡ Äڵ带 ¸î ÁÙ Ãß°¡ÇÏ¸é °¡´ÉÇÏ´Ù.

- °³¹ß ½Ã »ç¿ëÇÑ ¾Èµå·ÎÀÌµå ¹öÀüÀº ŶĹÀ¸·Î ¾Èµå·ÎÀÌµå ¹öÀü°ú Manifest¿¡¼­ ¼³Á¤ÇÑ Å׸¶¿¡ µû¶ó µðÀÚÀÎÀÌ ´Ù¸£´Ù.

- MainActivity.java¿¡¼­ onCreate ÇÏ´Ü¿¡ ¾Æ·¡ÀÇ Äڵ带 Ãß°¡Çϸé À§¿Í °°ÀÌ ¸Þ´º°¡ »ý¼ºµÈ´Ù.
 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// ¸Þ´º Ãß°¡
		menu.add(0, 0, Menu.NONE, "About");
		menu.add(0, 1, Menu.NONE, "½´¾ØÂô");
		 

		// SubMenu Ãß°¡
		SubMenu subMenu = menu.addSubMenu("¼³Á¤");

		// ¸Þ´º (0~7Áß) 1À» ´©¸£¸é ³ª¿À´Â SubMenu

		subMenu.add(1, 5, Menu.NONE, "Çϳª");
		subMenu.add(1, 6, Menu.NONE, "µÑ");
		subMenu.add(1, 7, Menu.NONE, "¼Â");

		menu.add(0, 2, Menu.NONE, "»èÁ¦");
		menu.add(0, 3, Menu.NONE, "¸ÞÀϺ¸³»±â");
		menu.add(0, 4, Menu.NONE, "Ä«¸Þ¶ó");
		return true
	}

  
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case 0:
				Toast.makeText(MainActivity.this, "About", Toast.LENGTH_SHORT).show();
				break
			case 1:
				Toast.makeText(MainActivity.this, "½´¾ØÂô", Toast.LENGTH_SHORT).show();
				break
			case 2:
				Toast.makeText(MainActivity.this, "»èÁ¦", Toast.LENGTH_SHORT).show();
				break
			case 3:
				Toast.makeText(MainActivity.this, "¸ÞÀϺ¸³»±â", Toast.LENGTH_SHORT).show();
				break
			case 4:
				Toast.makeText(MainActivity.this, "Ä«¸Þ¶ó", Toast.LENGTH_SHORT).show();
				break
			case 5:
				Toast.makeText(MainActivity.this, "Çϳª", Toast.LENGTH_SHORT).show();
				break
			case 6:
				Toast.makeText(MainActivity.this, "µÑ", Toast.LENGTH_SHORT).show();
				break
			case 7:
				Toast.makeText(MainActivity.this, "¼Â", Toast.LENGTH_SHORT).show();
				break
			default:
				break
			}
	 
		return super.onOptionsItemSelected(item);
	}


Áß°£ÀÇ SubMenu´Â ¸Þ´º¸¦ Çѹø ´©¸£°í 2Â÷·Î Ãß°¡µÇ´Â ¸Þ´ºÀÌ´Ù


¼³Á¤À» ´©¸£¸é



À§¿Í °°ÀÌ SubMenuÀÎ Çϳª, µÑ, ¼ÂÀÌ ³ª¿Â´Ù.

Äڵ忡¼­  onOptionsItemSelected  ¾Æ·¡ÀÇ °¢ ¸Þ´º¸¦ ¼±ÅÃÇßÀ» °æ¿ì¿¡ ¸Â°Ô Case¿¡ Äڵ带 ÀÛ¼ºÇÏ¸é µÈ´Ù.

 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.