Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 393
Nilanchala Panigrahy Avatar asked Jul 29 '11 11:07

Nilanchala Panigrahy


People also ask

How do I remove the title bar from my app?

NoActionBar theme prevents the app from using the native ActionBar class to provide the app bar. Thus it removes the title of every activity. Another way for removing the title specifically from an activity is by using a getSupportActionBar(). hide() method.

Which method is used to hide the activity title?

Just use getActionBar(). hide(); in your main activity onCreate() method.


2 Answers

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

like image 80
Androider Avatar answered Nov 10 '22 00:11

Androider


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();
like image 40
diyism Avatar answered Nov 10 '22 00:11

diyism