the simplest usage of the menu(Android Development)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了the simplest usage of the menu(Android Development)相关的知识,希望对你有一定的参考价值。
1.create menu directory
2.create the menu resource file(use the <item> label)
3.override the methor onCreateOptionsMenu(Menu menu) like this:
1 public boolean onCreateOptionsMenu(Menu menu) { 2 3 getMenuInflater().inflate(R.menu.main,menu); 4 5 return true; 6 7 }
4.override the click methor onOptionsItemSelected(MenuItem item) like this:
public boolean onOptionsItemSelected(MenuItem menuItem) { switch(menuItem.getItemId()) { case R.id.add_item: Toast.makeText(this,"You Clicked the Add Item",Toast.LENGTH_SHORT).show(); break; case R.id.remove_item: Toast.makeText(this,"You Clicked the Remove Item",Toast.LENGTH_SHORT).show(); break; default: break; } return true; }
以上是关于the simplest usage of the menu(Android Development)的主要内容,如果未能解决你的问题,请参考以下文章