Android: Hide ActionBar, keep Tabs

南楼画角 提交于 2019-12-04 09:59:24

问题


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!


回答1:


You can have an empty Actionbar, then the tabs will occupy the space:

getSupportActionBar().setDisplayShowHomeEnabled(false);              
getSupportActionBar().setDisplayShowTitleEnabled(false);



回答2:


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;
}



回答3:


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);



回答4:


Ahmad's answer is correct but it requires API 11. For supporting lower APIs, use this code -

setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

To enable it, use -

setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)


来源:https://stackoverflow.com/questions/14989372/android-hide-actionbar-keep-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!