隐藏Android的标题栏,仅在横向模式下

问题描述:

我有一个活动,要具备这些条件:隐藏Android的标题栏,仅在横向模式下

  • 我的活动在纵向模式下的标题栏。
  • 当我将设备转到横向模式时,标题栏会隐藏。
  • 通过在Manifest中使用“configChanges”,当进入风景模式时,不应该重新创建活动。

我知道这个问题之前被问过,但没有找到正确的答案。

请帮帮忙,在此先感谢...

+0

你尝试过这么远吗? –

+0

您可以通过configChanges回调隐藏标题栏,就像您在横向模式中提到的那样 – kirtan403

+0

我已经使用: android:configChanges =“orientation | screenSize” 在清单中停止重新创建更改屏幕方向后的活动。 – Arantik

添加在style.xml

<style name="generalnotitle" parent="Theme.AppCompat.Light" > 
    <item name="android:windowNoTitle">true</item> <!-- //this --> 
</style> 

加入manifiest文件活动,

android:theme="@style/generalnotitle"> 

要获得设备的方向

int display_mode = getResources().getConfiguration().orientation; 


if (display_mode == Configuration.ORIENTATION_LANDSCAPE) { 

     getSupportActionBar().hide(); //<< this 

    } else { 



    } 

setContentView(R.layout.activity_main); 

无标题栏Portrait Mode with title bar

风景模式

Lanscape mode without title bar

+0

感谢您的回答,但添加此代码来显示,不会隐藏标题栏,只是透明。 – Arantik

+0

好吧,我会创建测试,请等待修改代码。 –

+0

,而且java代码根本不做任何事情。 谢谢阿卡什kumar ... – Arantik