How to hide the title bar through code in android

I want to hide the title using code for some of my actions.

I 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 works for full screen, but shows the name of the application. Lets say that for my splash screen I want to hide my title. The first line of code crashes my application. Please help me if we can do this using the code.

thanks.

+5
source share
5 answers

To hide the 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 display the 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(); 
+8
source
 this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

You must call this before your setContentView () method , did you do it?

You can always do this in your manifest by adding android:theme="@android:style/Theme.NoTitleBar" to your activity

+20
source

If you are using API 11 and above

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

to remove the application header , then add this line

requestWindowFeature(Window.FEATURE_NO_TITLE);

before setContentView (R.layout.main);

+2
source

Make sure you call setContentView after these two lines

0
source

Source: https://habr.com/ru/post/895812/


All Articles