安卓:如果然后更改菜单? [英] Android: if this then change menu?

查看:165
本文介绍了安卓:如果然后更改菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的选项菜单和其功能变化时,我就命令。

因此​​,例如:布局是全屏,选项和退出。当我点击全屏,我想要的菜单更改,以便它现在的样子:退出全屏,选项,退出

我不知道编码尚未所以我希望你能举一些例子说明code一切。

在此先感谢!

这是code的菜单:

  @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){     。getMenuInflater()膨胀(R.menu.menu,菜单);
        返回true;
    }    公共布尔onOptionsItemSelected(菜单项项){
        开关(item.getItemId())
        {            案例R.id.help:
                意向意图=新意图(这一点,help.class);
                startActivity(意向);
            打破;            案例R.id.exitfullscreen:
                完();
            打破;            案例R.id.quit:
                 moveTaskToBack(真);
            打破;            默认:
            打破;
        }
        返回false;


解决方案

按照你的意见试试这个:

在您的fullscreen.java

  @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){     。getMenuInflater()膨胀(R.menu.menu,菜单);
        菜单项亩= menu.findItem(R.id.exitfullscreen);
        mu.setTitle(退出全屏);
        返回true;
    }

P.S。应用此何时何necssary更改菜单项的文本(标题)。

I want the options menu and its functions to change when I command it to.

So for example: layout is Fullscreen, options and quit. When I click on fullscreen, I want the menu to change so that it now looks like: Exit Fullscreen, options, quit.

I dont know everything in coding yet so I hope you can give some example code.

Thanks in advance!

this is the code for the menu:

 @Override
    public boolean onCreateOptionsMenu (Menu menu) {

     getMenuInflater().inflate (R.menu.menu, menu);
        return true;
    }



    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) 
        {

            case R.id.help:
                Intent intent = new Intent(this, help.class);
                startActivity(intent);
            break;

            case R.id.exitfullscreen:
                finish();  
            break;

            case R.id.quit:
                 moveTaskToBack(true);
            break;



            default:    
            break;
        }
        return false;

解决方案

Following your comments try this:

in your fullscreen.java

 @Override
    public boolean onCreateOptionsMenu (Menu menu) {

     getMenuInflater().inflate (R.menu.menu, menu);
        MenuItem mu = menu.findItem(R.id.exitfullscreen);
        mu.setTitle("Exit Full Screen");
        return true;
    }

P.S. Apply this where and when necssary to change your menu items text (title).

这篇关于安卓:如果然后更改菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆