创建全屏 activity 但保留通知栏

Creates a full screen activity but retains the notification bar

我在设计套件时正在创建一个音乐应用程序,我想我需要创建一个全屏activity我试过了

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

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

如何操作?

谢谢!

在您的主题中:

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

在你的 activity 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);

从您的代码中删除 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 这一行,然后将更改放入您的 activity 样式中。

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

把这段代码放在上面setContentView()

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