【问题标题】:Creates a full screen activity but retains the notification bar创建全屏活动但保留通知栏
【发布时间】:2018-06-01 16:06:23
【问题描述】:

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

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

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

如何做到这一点?

谢谢!

【问题讨论】:

  • 可以在AndroidMenifest.xml中设置
  • @Binh Cao 试试我的答案
  • 您希望通知栏保持可见??
  • 是的,我希望通知栏仍然显示在我的应用中
  • @Bink Cao 检查我的新答案

标签: java android fullscreen


【解决方案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);

【讨论】:

  • 它隐藏了通知栏
  • 试试我的新答案,我以为你想隐藏栏所以检查我的新答案
  • @BinhCao 我的回答很简单:)
  • @BinhCao 如果可能的话接受我的回答,祝你编码愉快
  • 对不起,我当时正在尝试 Paraskeva Ntsounos 方式
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    将此代码放在setContentView()上方

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

    【讨论】:

    • 它隐藏了通知栏
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    相关资源
    最近更新 更多