如何编程更改选项菜单中的项目? [英] How to programatically change an item in the options menu?

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

问题描述

在上的菜单按钮,用户点击我present一些菜单项。其中之一是一个退出按钮。我希望能够改变的登录和退出这取决于我跟踪一个布尔值的文本。我如何可以以编程方式更改菜单中的文本?

When the user clicks on the Menu button I present a few menu items. One of them is a Sign Out button. I want to be able to change the text between "Sign In" and "Sign Out" depending on a boolean value I am tracking. How can I programmatically change the text in the menu?

推荐答案

您想覆盖在活动prepareOptionsMenu功能。有通过一个菜单参数,你可以简单地找到你想要显示/隐藏的菜单项(或更改图像和文本),并返回true。

You want to override the onPrepareOptionsMenu function in the Activity. There is a menu parameter passed, you can simply find the menuitem that you want to show/hide (or change the image and text) and return true.

<一个href=\"http://developer.android.com/reference/android/app/Activity.html#on$p$ppareOptionsMenu%28android.view.Menu%29\"相对=nofollow>在prepareOptionsMenu

这篇关于如何编程更改选项菜单中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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