[英]Is there a way to change the text of an Action Bar Menu Item when I touch the menu item in Android?
当我触摸此“编辑”按钮时,我希望它更改为“完成”。 有没有办法做到这一点?
我试过了,但仅在打开右侧菜单时有效:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// change the text here.
return super.onPrepareOptionsMenu(menu);
}
我认为在某个时候您会给菜单充气,是吗?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.some_menu_layout, menu);
return true;
}
因此,您可以进入菜单(在本例中为res/menu/some_menu_layout.xml
),然后找到要查找的菜单项的android:id
。 然后,您应该可以使用menu.findItem(theId).setTitle("Done");
。 (为此,您可能必须将Menu
变量另存为本地成员。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.