Binh Cao
Binh Cao

Reputation: 47

Creates a full screen activity but retains the notification bar

I'm creating a music application when designing kits, I think I need to create a full screen activity I have tried

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

But that's not what I want, I want full screen but still retain notification bar

enter image description here

How to do this?

Thank!

Upvotes: 1

Views: 114

Answers (3)

Paraskevas Ntsounos
Paraskevas Ntsounos

Reputation: 1777

In your theme:

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

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

Upvotes: 1

Saaanty
Saaanty

Reputation: 195

Put this code above setContentView()

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

Upvotes: 1

Anand jain
Anand jain

Reputation: 89

Remove getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this line from your code and just put change int your activity style.

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

Upvotes: 1

Related Questions