How Can we hide title bar while using action bar?
Solution 1
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. :)
Solution 2
I hide the title bar by adding the following lines of code:
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
hope this helps :)
Solution 3
to hide all the title bar and keep only the action bar use this code:
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
it worked for me
Solution 4
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.
Solution 5
see this answer to grammatically show/hide titleBar from the ActionBarSherlock ..
Comments
-
Arci almost 2 years
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 theActionBar
How do I remove/hide the title bar? Please note that I'm not referring to the title of the action bar. I'm referring to the title bar above the action bar. I'm running my application on an Android 2.3 device.Below is my code: (My class extends
SherlockFragmentActivity
.)super.onCreate(savedInstanceState); setTheme(R.style.Theme_Sherlock); this.requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionbar = getSupportActionBar(); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //I get the NullPointerException here. //... setContentView(R.layout.tab_navigation);
-
Bartek over 10 yearsThe explanation of the code vs. manifest issue is in my answer.
-
Azahar about 10 yearsThe method getSupportActionBar() is undefined for the type
-
Khaledvic about 10 years@Azahar you should use getActionBar() if you aren't using support libraries
-
panchicore almost 10 yearsand if you are using menu layouts, set them as android:showAsAction="never" in menu.xml