Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding title bar / notification bar when device is oriented to landscape

I want my title bar to be hidden when I turn my device to landscape. I have seen the XML option to hide the title bar, and the following example of doing it programmatically:

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

BUT, I am using configChanges parameter for orientation and screenSize, so my activity is not re-created again when it is orienting to landscape (I'm doing this for some reasons). So I cannot use the above methods as these calls need to be made before setContentView().

So any ideas? Thank you.

like image 707
g.revolution Avatar asked Aug 08 '12 02:08

g.revolution


1 Answers

was searching for an answer, ended up here, put the pieces together and here they are:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
like image 190
dldnh Avatar answered Nov 03 '22 00:11

dldnh