首页 > 移动平台 > 详细

the simplest usage of the menu(Android Development)

时间:2017-10-02 22:43:50      阅读:333      评论:0      收藏:0      [点我收藏+]

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)

原文:http://www.cnblogs.com/rotaux/p/7622783.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!