Hiding app title bar in Android pager

2019-05-03 09:26发布

问题:

Can anyone tell how to hide the app title bar in Pager fragment.

回答1:

This should be enough:

ActionBar bar = getActionBar(); // you might need to use getSupportActionBar() based on your project setup
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(false);


回答2:

Warren is correct. And if you want to hide it in your theme, you can do it by inheriting from a theme that does not display it:

  • For pre-Honeycomb styles:

    <style name="HiddenActionBar" parent="@android:style/Theme">
    </style>
    
  • For Honeycomb+:

    <style name="HiddenActionBar" parent="@android:style/Theme.Holo.NoActionBar">
    </style>
    

I personally prefer this method because it frees your classes from UI-related code and can easily be set for every Activity by changing the theme of your application in the manifest.