ANDROID FULL SCREEN ACTIVITY
In Android, a Full-Screen Activity refers to an activity where the app occupies the entire screen, hiding the status bar, navigation bar, and other UI elements, providing an immersive experience. Full-screen modes are commonly used in apps such as games, media players, and other applications where you want to give users an uninterrupted experience.
There are different ways to achieve a full-screen activity in Android. Below are the most common methods to make an activity full-screen.
1. Full-Screen Activity using the Manifest File
You can declare your activity as full-screen directly in the AndroidManifest.xml file by using the android:theme attribute with a special full-screen theme. This approach hides the status bar and other UI elements.
Steps:
- Declare the Theme in
AndroidManifest.xml:
In your AndroidManifest.xml file, you can specify the theme for your activity like this:
<activity
android:name=".FullScreenActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
In this case, @android:style/Theme.NoTitleBar.Fullscreen is the default theme that hides both the title bar and the status bar, making the activity full-screen.
2. Programmatically Make an Activity Full-Screen
You can also make an activity full-screen programmatically in your activity’s onCreate() method. This gives you more control over when and how to hide the status bar or navigation bar.
Steps:
- Using
Windowto Hide Status and Navigation Bars:
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 the status bar and the navigation bar
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
Explanation of the Flags:
SYSTEM_UI_FLAG_FULLSCREEN: Hides the status bar.SYSTEM_UI_FLAG_HIDE_NAVIGATION: Hides the navigation bar (back, home, and recent buttons).SYSTEM_UI_FLAG_IMMERSIVE_STICKY: Keeps the system bars hidden until the user interacts with the screen.
This method ensures that the activity remains full-screen until the user performs an action that reveals the system bars (e.g., a swipe or a button press).
3. Full-Screen Activity with Immersive Mode
Immersive mode allows you to hide both the status bar and the navigation bar, and the system bars will only reappear when the user interacts with the screen.
You can combine the full-screen flags and immersive mode in your activity to create a more seamless full-screen experience.
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);
// Enable immersive full-screen mode
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
4. Handle Full-Screen Mode on Orientation Change
If your app handles both portrait and landscape modes, you might want to ensure the full-screen mode is preserved when the orientation changes. This can be done by overriding the onResume() and onPause() lifecycle methods to re-enable full-screen mode whenever the activity is resumed.
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);
}
@Override
protected void onResume() {
super.onResume();
// Re-enable full-screen mode
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
@Override
protected void onPause() {
super.onPause();
// Optionally, disable full-screen mode (restore default UI)
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_VISIBLE
);
}
}
This ensures that full-screen mode remains active even if the user changes the screen orientation.
5. Full-Screen Activity with a Custom Theme
If you want to control the appearance of the status bar, navigation bar, and other UI elements more extensively, you can create a custom theme in your res/values/styles.xml file.
Steps:
- Define a Custom Full-Screen Theme in
styles.xml:
<resources>
<style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Hide status bar and navigation bar -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
- Apply the Custom Theme in
AndroidManifest.xml:
<activity
android:name=".FullScreenActivity"
android:theme="@style/AppTheme.FullScreen">
</activity>
6. Full-Screen Activity with ActionBar Hiding
If your app has an ActionBar (also known as the AppBar), you might want to hide it when transitioning into full-screen mode.
Steps:
- Hide the ActionBar programmatically:
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 the ActionBar
getSupportActionBar().hide();
// Enable full-screen mode
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
This method hides the ActionBar in addition to enabling full-screen mode.
Conclusion
Creating a full-screen activity in Android can significantly enhance the user experience, especially in apps like games or media players that require uninterrupted focus on content. You can implement full-screen mode using different methods, whether by declaring it in the AndroidManifest.xml or programmatically using system UI flags.
Depending on the use case, you can choose to hide the status bar, navigation bar, or even the ActionBar to achieve a true full-screen experience. Always ensure to handle orientation changes and other lifecycle events to maintain the full-screen state seamlessly across different scenarios.

0 Comments