7

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.

6 Answers 6

22
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

Sign up to request clarification or add additional context in comments.

2 Comments

flag as answered then, please :)
This works, but even if I call this before setContentView(),the title shows itself for a second and than the activity is displayed full screen. Has someone noticed this, and knows a solution??
11

To hide title bar and status bar:

try
   {((View)act.findViewById(android.R.id.title).getParent()).setVisibility(View.GONE);
   }
catch (Exception e) {}
act.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
act.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
view.requestLayout();

To show title bar and status bar:

try
   {((View)act.findViewById(android.R.id.title).getParent()).setVisibility(View.VISIBLE);
   }
catch (Exception e) {}
act.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
act.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
view.requestLayout();

2 Comments

Can I just ask, in the end you call requestLayout on what view? Also, the first line of your answer (the one that suppose to hide the title) crashes my app :s
yeah me too confused.
8

If you are using API 11 and above

ActionBar actionBar = getActionBar();
actionBar.hide(); // slides out
actionBar.show(); // slides in

2 Comments

i want to remove title if<api 11 and want to show title bar if api>11
I had to change the code to ActionBar actionBar = getSupportActionBar() to use the androidx library.
2

for remove Application Titlebar then add this line

requestWindowFeature(Window.FEATURE_NO_TITLE);

before setContentView(R.layout.main);

Comments

0

Make sure you are calling setContentView after these 2 lines

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.