java Android:隐藏操作栏,保留标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14989372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Hide ActionBar, keep Tabs
提问by josephoneill
To keep this simple: I have tabs in my actionbar, but the action bar take up too much space. I want that extra space. I need a way to hide the action bar, yet keep my tabs. Is there anyway to do this? Or is there a way I can get the tabs built into the action bar like it is in landscape mode? Thanks!
为了简单起见:我的操作栏中有选项卡,但操作栏占用了太多空间。我想要那个额外的空间。我需要一种方法来隐藏操作栏,同时保留我的标签。有没有办法做到这一点?或者有没有办法像在横向模式下一样将选项卡内置到操作栏中?谢谢!
回答by Ahmad
You can have an empty Actionbar, then the tabs will occupy the space:
您可以有一个空的 Actionbar,然后选项卡将占据空间:
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
回答by Psypher
Try the below code:
试试下面的代码:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
Also remove the below in code which is added default when project is created:
还要删除以下代码,该代码在创建项目时默认添加:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
回答by Rohit
This did the trick for me
这对我有用
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
I also commented the line
我也评论了这一行
getMenuInflater().inflate(R.menu.main, menu);
回答by Confuse
Ahmad's answer is correct but it requires API 11. For supporting lower APIs, use this code -
Ahmad 的回答是正确的,但它需要 API 11。要支持较低的 API,请使用此代码 -
setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
To enable it, use -
要启用它,请使用 -
setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)