创建全屏活动但保留通知栏

时间:2018-06-01 16:06:24

标签: java android fullscreen

我在设计工具包时创建了一个音乐应用程序,我想我需要创建一个我尝试过的全屏活动

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

但那不是我想要的,我想全屏但仍保留通知栏

enter image description here

怎么做?

感谢!

3 个答案:

答案 0 :(得分:1)

在你的主题中:

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>

在你的活动onCreate:

Window window = getWindow();
WindowManager.LayoutParams winParams = window.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
window.setAttributes(winParams);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

答案 1 :(得分:1)

从代码中删除getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);这一行,然后将change int置于您的活动样式中。

   <style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

的Manifest.xml

  <activity android:name=".Login"
        android:theme="@style/LoginTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

答案 2 :(得分:1)

将此代码置于setContentView()

之上
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);