'How to hide the title bar through code in android
I want to hide the title bar using code for some of my activities.
I have used the following code
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
the second line is working for full screen but it shows the application title. Lets say for my splash screen i want to hide my title. The 1st line of code crashes my application. Please help me if we can do it using code.
thanks.
Solution 1:[1]
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
You should call this before your setContentView() method, did you do that?
You could always do it in your manifest by adding android:theme="@android:style/Theme.NoTitleBar" to your activity
Solution 2:[2]
If you are using API 11 and above
ActionBar actionBar = getActionBar();
actionBar.hide(); // slides out
actionBar.show(); // slides in
Solution 3:[3]
for remove Application Titlebar then add this line
requestWindowFeature(Window.FEATURE_NO_TITLE);
before setContentView(R.layout.main);
Solution 4:[4]
Make sure you are calling setContentView after these 2 lines
Solution 5:[5]
Update for 2022. Works in Android 9+ (at least) and you can call it after setContentView()
// Hide action bar Objects.requireNonNull(getSupportActionBar()).hide();
// Show action bar Objects.requireNonNull(getSupportActionBar()).show();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Niranj Patel |
| Solution 2 | Paul |
| Solution 3 | Niranj Patel |
| Solution 4 | Niranj Patel |
| Solution 5 | Lee Harding |
