How to make a particular Activity Fullscreen? [Solution] (Android Development)

Making an Activity Fullscreen is not very tough.

But the question is what exactly you want to do. Do you have an app which has an actionbar(toolbar or title bar)
and you just want a particular activity to not display the actionbar(toolbar) ? like this:

BEFORE: with actionbar
BEFORE: with actionbar
AFTER: without actionbar
AFTER: without actionbar

Or do you want your Activity to be completely Fullscreen(called immersive) such that it covers/hides the status bar(notification bar where you see the battery and stuff) or navigation bar? like this:

fullscreen activity 4.PNG

The solution to the former question: that is, to hide the actionbar follow the following steps:

  • Open your AndroidManifest.xml file and add the following code to the activity that you want to be displayed wihout the actionbar:
 android:theme="@style/Theme.AppCompat.NoActionBar"

So that your activity looks like this:
fullscreen activity 1

However, the above code may not always work depending on the theme you are using.
So basically what you need to do is add a theme without an action bar to the activity code.
So just try typing ‘No’ inside the theme as shown and wait for the Android Studio or whatever IDE you are using to suggest a theme suitable for you.

android:theme="@style/No"

fullscreen activity 2If the above method to hide the actionbar did not work for you then don’t worry, I show another way to hide the action bar later on in the article. That method is using JAVA.

  • However, to make your app completely Fullscreen such that it even hides the status bar follow the following steps:

For Android 4.0(API level 14) and lower:
The official article by google suggests to add the following code to the app’s mainfest file:

where ‘Holo’ is the theme name. Note: It may be different for your case.
But it didn’t work for me as the above code threw an error when I tried it. So I am not sure about this method.

For Android 4.1(API level 16) or higher:

You can hide the status bar on devices running Android 4.1 or higher by adding the following code to the activity’s OnCreate Method:

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.

You can even hide the actionbar by adding the following snippet to the OnCreate Method of your Activity:

ActionBar actionBar = getActionBar();
actionBar.hide();

So now I’ve shown you two ways to hide the Action Bar for your activity.

NOTE: Though the above method hides the status bar, it is not perfect and probably not what you wanted .

Why do I say that?
It’s cause when I tested this method on my Sony Xperia C running Jelly Bean the status bar was hidden permanently.
Meaning that the user had no way of accessing the status bar once the activity went full-screen.
Though what I expected or rather wanted was to have the status bar hidden but in a way such that the user could access the status bar by swiping downwards and then when they swiped up the status bar should disappear(hide).

On another device running Android 5 (API Level 21 or 22 ,Lollipop) I noticed that the user could access the status bar by swiping downwards but once it was accessed it never disappeared.

Fix:

In this Official Article by Google they have provided a way to provide the users with Android 4.4(API level 19), with a fully immersive experience by using SYSTEM_UI_FLAG_IMMERSIVE flags.

When you use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag, an inward swipe in the status bar(notification) areas causes the bars to temporarily appear in a semi-transparent state. The bar automatically hides again after a short delay, or if the user interacts with the middle of the screen.

To implement this just add the following method to your activity:

 @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        View decorView = getWindow().getDecorView();
        if (hasFocus) {
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
    }

example:
fullscreen activity 7

 

 

 

 

[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.