How to create an optionsMenu in an Android's T

2020-04-18 07:30发布

I try to create options menu in a TabActivity.

But instead of it I see for every activity within tabbar its own options menu.

Is it possible change this behaviour? And if yes, how?

Thank you

1条回答
Deceive 欺骗
2楼-- · 2020-04-18 08:07

Ok. I think I know the solution.

If there onCreateOptionsMenu in any activity within tabbar, so it should be modified a bit:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // is activity withing a tabactivity
    if (getParent() != null) 
    {
        return getParent().onCreateOptionsMenu(menu);
    }
    ...
}
查看更多
登录 后发表回答