How Can we hide title bar while using action bar?

前端 未结 10 2012
闹比i
闹比i 2021-02-12 14:43

I\'m using ActionBarSherlock and I\'m trying to hide the title bar of my application but whenever I do that, I get a NullPointerException when accessing the A

相关标签:
10条回答
  • 2021-02-12 15:02

    Try it:

    setTheme(R.style.Theme_Sherlock_NoActionBar);
    
    0 讨论(0)
  • 2021-02-12 15:04

    I was searching for an answer for this. Found one solution.

    actionBar = getActionBar();
    actionBar.hide();
    

    The above snippet will remove the tab title and slider. Hope it helps.

    0 讨论(0)
  • 2021-02-12 15:07

    I had the same problem. None of these answers worked for me, I still had a glimpse of the Title Bar showing right before Actionbar loaded.

    I had to set the Activity theme to NoActionBar in the Manifest:

    android:theme="@style/Theme.Sherlock.NoActionBar"
    

    And then set the theme back inside my Activity right before setContentView():

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setTheme(R.style.Theme_Custom);
        setContentView(R.layout.activity_home);
    }
    

    This still loaded my custom theme and I no longer see a glimpse of the Title bar when activity loads

    0 讨论(0)
  • 2021-02-12 15:10

    Found the solution on this one. If you declare your theme on AndroidManifest.xml, the title bar will go away on its own. Although, I don't why it only works when declared on AndroidManifest.xml and not on code.

    The reason for the NullPointerException is that ActionBar is synonymous to the TitleBar on higher versions (ICS and newer). By using the compatibility library and ActionBarSherlock, hiding the TitleBar will also mean hiding the ActionBar.

    Below is how you can set your application to use Sherlock's theme: (You should add it on the application's tag)

    android:theme="@style/Theme.Sherlock"
    

    If you know how to hide the title bar on code, please feel free to modify my answer to include your answer. And if anyone can explain why it only works on the manifest file and not on code if would be nice. :)

    0 讨论(0)
  • 2021-02-12 15:10
        <activity android:name=".xxxxxActivity"
                  android:theme="@style/Theme.Sherlock.NoActionBar"/>
    
    0 讨论(0)
  • 2021-02-12 15:17

    I hide the title bar by adding the following lines of code:

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

    hope this helps :)

    0 讨论(0)
提交回复
热议问题