动态更改工具栏的外观 [英] Changing a Toolbar appearance dynamically

查看:121
本文介绍了动态更改工具栏的外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态更改工具栏的外观在我的应用程序。它应该为Gmail应用;每当你点击一个电子邮件,工具栏和变化似乎有按钮,即G。斌,复制等怎么办呢?我困在这里pretty。谢谢你。

I'd like to dynamically change the appearance of a Toolbar in my app. It should work as the Gmail app; whenever you click on an email, the Toolbar changes and there appear buttons, e. g. Bin, Copy, etc. How to do it? I'm pretty stuck here. Thank you.

推荐答案

您只需通过获取IDS的项目在menu.xml文件并改变它们的可见性,当您从有形的,无形的,走了就好。
由于在启动他们是无形的,但是,他们的点击可见。

You can just get the items by ids in your menu.xml and change their visibility as when you like from visible , invisible , gone. As on start they are invisible but on click they become visible .

public boolean onPrepareOptionsMenu(Menu menu) 
{
MenuItem register = menu.findItem(R.id.menuregistrar);      
if(userRegistered) 
{           
    register.setVisible(false);
}
else
{
    register.setVisible(true);
}
return true;
} 

inshort它可以被写成:

inshort it could be written as:

 MenuItem register = menu.findItem(R.id.menuregistrar);      
  register.setVisible(!userRegistered);
  return true;

这篇关于动态更改工具栏的外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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