ANDROID FULL SCREEN MODE . If you want to know about ANDROID FULL SCREEN MODE , then this article is for you.

ANDROID FULL SCREEN MODE


Android Full-Screen Mode is a popular feature used to make an Android app or activity display without distractions, fully utilizing the screen real estate. It’s typically used in applications such as games, video players, and photo viewers, where you want to immerse the user in content without showing system UI elements like the status bar, navigation bar, or action bar.

Why Use Full-Screen Mode?

The full-screen mode allows users to enjoy content without the interruptions caused by system bars and other UI components. It’s ideal for:

  • Gaming apps that require immersive experiences.
  • Video apps where the user wants to view media without obstructions.
  • Photo or gallery apps where images need to take up the entire screen.

How to Enable Full-Screen Mode in Android

There are multiple ways to implement full-screen mode in Android, depending on what elements you want to hide (e.g., the status bar, the navigation bar, or the action bar).

Here’s how you can programmatically enter full-screen mode in an Android app:

1. Hiding Status Bar and Navigation Bar

You can hide the status bar (the bar at the top with time, battery, etc.) and the navigation bar (at the bottom with back, home, and recent buttons). This allows the activity to take up the full screen.

Code Example:

import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;

public class FullScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_screen);

        // Hide status bar and navigation bar
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN |               // Hide status bar
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |          // Hide navigation bar
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY           // Stick to full-screen until user interacts
        );
    }
}

Explanation of Flags:

  • SYSTEM_UI_FLAG_FULLSCREEN: Hides the status bar.
  • SYSTEM_UI_FLAG_HIDE_NAVIGATION: Hides the navigation bar.
  • SYSTEM_UI_FLAG_IMMERSIVE_STICKY: Keeps the system bars hidden even when the user interacts with the screen (i.e., swiping from the edge). The system bars will only reappear temporarily, then automatically hide again.

2. Hiding ActionBar (if present)

If your activity contains an ActionBar (the top toolbar with the app name and any actions), you can hide it for a cleaner, more immersive experience.

Code Example:

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class FullScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_screen);

        // Hide the ActionBar
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

        // Hide the status bar and navigation bar
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN |
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        );
    }
}

3. Make Full-Screen Persistent (Even on Orientation Changes)

Sometimes, the system might reset the full-screen mode when the device orientation changes (from portrait to landscape). To prevent this, you should ensure the full-screen mode is applied when the activity resumes.

Code Example for Persistent Full-Screen Mode:

import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;

public class FullScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_screen);
        
        // Initially set the full-screen mode
        setFullScreen();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // Reapply full-screen mode after orientation change
        setFullScreen();
    }

    private void setFullScreen() {
        // Hide status bar and navigation bar
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN |
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        );

        // Optionally hide ActionBar
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
    }
}

By calling setFullScreen() within both onCreate() and onResume(), you ensure the full-screen settings persist even after orientation changes.

4. Using Full-Screen Mode with No Action Bar in the Manifest

You can also define a custom theme in the AndroidManifest.xml file that applies full-screen mode by default.

Steps:

  1. Create a Full-Screen Theme: In res/values/styles.xml, create a custom theme that removes the title bar and sets the activity to full-screen:
<resources>
    <style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>
  1. Apply the Theme in the Manifest: In AndroidManifest.xml, apply this theme to the activity you want to make full-screen:
<activity
    android:name=".FullScreenActivity"
    android:theme="@style/AppTheme.FullScreen">
</activity>

This way, the activity will automatically be displayed in full-screen mode without needing to modify the code every time.


5. Immersive Mode for a Better Experience

If you want to ensure a smoother experience where the system UI is temporarily shown when the user interacts with the screen (e.g., swiping from the edges), you can use Immersive Mode. This allows the system UI to be temporarily shown and automatically hides again after a few seconds.

Code Example for Immersive Mode:

import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;

public class FullScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_screen);

        // Set immersive full-screen mode
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN |                    // Hide status bar
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |               // Hide navigation bar
            View.SYSTEM_UI_FLAG_IMMERSIVE |                     // Enable immersive mode
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY                // Sticky immersive mode
        );
    }
}

In Immersive Mode, the system UI is hidden until the user swipes from the edge, and once the system UI appears, it automatically hides again after a short time.


6. Handling Full-Screen Mode on Lockscreen

For some use cases, you may want to prevent users from exiting full-screen mode when they press the home or back button. For instance, in a video player app, you might want to ensure the user stays in full-screen mode while watching content.

However, Android doesn't officially support locking full-screen mode in this manner, but you can prevent screen dimming and turn off the back button for certain activities if needed.


Conclusion

Implementing Full-Screen Mode in your Android app is easy and can enhance the user experience significantly. Whether you’re creating a game, media app, or any other immersive experience, using the flags to hide the system UI elements ensures the content takes center stage.

  • Hide the status bar and navigation bar with SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION.
  • Use Immersive Mode to allow temporary display of system UI when swiping from the edges.
  • Hide ActionBar if present to maximize screen space.
  • Reapply full-screen mode in onResume() to handle orientation changes.

With these techniques, you can create a truly immersive full-screen experience for your Android users.