当设备面向横向时,隐藏标题栏/通知栏 [英] Hiding title bar / notification bar when device is oriented to landscape

查看:123
本文介绍了当设备面向横向时,隐藏标题栏/通知栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将设备变为横向时,我希望隐藏标题栏。我已经看到了用于隐藏标题栏的XML选项,以及以编程方式执行此操作的示例:

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

但我正在使用 configChanges 参数 orientation screenSize ,所以我的活动在面向风景时不会再次重新创建(我正在做这有一些原因)。所以我不能使用上面的方法,因为这些调用需要在 setContentView()之前进行。

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

所以任何想法?谢谢。

推荐答案

正在寻找答案,最后来到这里,把各个部分放在一起,这里是:

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

这篇关于当设备面向横向时,隐藏标题栏/通知栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆