在我的应用程序中,我有将近8个菜单,我有两种类型的用户管理和客户端
对于Admin,我需要显示所有8个manus,对于用户,我需要为用户显示2个菜单。
为此,我给了这个
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.m_mymenu, menu);
return true;
}在我的代码出现在简历之后,我将在下面添加一个
@Override
public boolean onOptionsItemSelected(MenuItem item) {
SharedPreferences s = getSharedPreferences(my_New_SP, 0);
HashMap<String, String> map= (HashMap<String, String>) s.getAll();
int id = item.getItemId();
if (map.get("usage").equals("Admin"))
{
if (id == R.id.abc) {
Intent mypIntent = new Intent(this, Myp.class);
startActivity(mypIntent);
return true;
}
.
.
.
.
else if (id == R.id.web1) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about1) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
}
if (map.get("usage").equals("User"))
{
if (id == R.id.web1) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about1) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
}
return super.onOptionsItemSelected(item);
}因此,在这里的选项菜单中,我只想显示两个用户和8个管理员。
但是当我选择它作为用户时,我能够看到所有的菜单,其中只有两个在工作。所以在这里我只想显示工作菜单应该隐藏起来。
有人能建议我做这种事吗..。
这里的菜单来自android菜单,而不是动态菜单.
发布于 2016-04-04 08:55:47
private Menu menu1;现在在oncreate中,做这样的事情
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
menu1 = menu.findItem(R.id.web1);
menu1.setVisible(false);
return true;
}现在,您可以在任何您想要的地方隐藏/显示menu1。对其他选项也这样做
https://stackoverflow.com/questions/36397968
复制相似问题