动态更改工具栏的外观工具栏、外观、动态

2023-09-06 07:25:31 作者:痴情废物

我想动态更改工具栏的外观在我的应用程序。它应该为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;