Android: making a fullscreen application
Asked Answered
D

17

60

What is the simplest change that I can make to a new Blank Activity, as created by the latest version of Android Studio, to get the app to appear fullscreen?

I want to create a fullscreen Android application. I'm working with Android Studio. This post suggests that I add a line such as ...

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"

... to the AndroidManifest.xml file, as shown below:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.lexogram.james.blackslate" >

            <application
                    android:allowBackup="true"
                    android:icon="@drawable/ic_launcher"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme" >
                    <activity
                            android:name="com.lexogram.james.blackslate.MainActivity"
                            android:label="@string/app_name"
                            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
                            <intent-filter>
                                    <action android:name="android.intent.action.MAIN" />

                                    <category android:name="android.intent.category.LAUNCHER" />
                            </intent-filter>
                    </activity>
            </application>

    </manifest>

When I do this, the app compiles but it crashes on launch. If I remove the line, the app runs fine, but with the action bar and a title bar, as also noted by other users.

This is my first attempt at creating an Android app, so my app is hardly altered from the original Hello World example.

EDIT: I created a new project, and made just this one change to it. Here is an extract from the error log:

FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lexogram.james.test/com.lexogram.james.test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...

NOTE: I am testing on a old Samsung SGH-T499Y, running Android 2.2 (Froyo)

Duodenal answered 24/10, 2014 at 7:23 Comment(6)
What error do you get when the app crashes? Check in the LogCat output in Android Studio (crash errors always start with FATAL and are colored red).Midgett
Are you using anything from a custom theme (some attributes perhaps) that wouldn't be available in the full screen default theme? Does your view render if you select that theme on the review screen (I'm using Eclipse so don't know what the equivalent is in Android Studio). Your logs should tell you what's going on and what the exact error is but for me, this was usually the problem when changing themes for activities.Aculeate
Are you call getActionBar() when you use theme Holo.Light.NoActionBar ? It return null, if you setTitle("") or something like that it will be NullPointerException .Fruge
@Aculeate The view renders in the Preview screen in Android Studio. However, when I preview on an emulator that corresponds to my real device, I get this warning: Rendering Problems Failed to parse file /Applications/ Third Party/Android/Android Studio.app/sdk/platforms/android-21/data/res/color/secondary_text_holo_dark.xml <item> tag requires a 'drawable' attribute or child tag defining a drawable.Duodenal
The warning above does not appear if I preview on a more modern emulator, such as API 20: Android 4.4W.Duodenal
check My Answer. you can get a quick and easy solution on this page ...Kao
D
85

You are getting this problem because the activity you are trying to apply the android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"> to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Extend your activity from Activity rather than from ActionBarActivity

You might have to change your Java class accordingly little bit.

If you want to remove status bar too then use this before setContentView(layout) in onCreateView method

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
Damian answered 24/10, 2014 at 11:36 Comment(5)
You must be extending your activity class from ActionBarActivity, change that to Activity. ActionBarActivity can't be switched to full screen.Damian
First I got an error after making this change, but then I realized that it also requires me to replace import android.support.v7.app.ActionBarActivity with import android.app.Activity, and now I see no Action Bar, but the Status Bar is still present, so the app is still not completely fullscreen.Duodenal
Thank you Rohit5k2. Your edited version gives me the result I was hoping for.Duodenal
But this code only hides the status bar. is there any method to hide the system Navigation bar also.Petulance
This method is now deprecatedCaterer
K
63

Just add the following attribute to your current theme:

<item name="android:windowFullscreen">true</item>

For example:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/orange</item>
    <item name="colorPrimaryDark">@android:color/holo_orange_dark</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>
Kaciekacy answered 1/11, 2016 at 8:24 Comment(0)
P
20

just do this in your manifest file in your activity tag

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
Peerless answered 5/8, 2015 at 20:14 Comment(0)
L
13

in my case all works fine. See in logcat. Maybe logcat show something that can help you to resolve your problem

Anyway you can try do it programmatically:

 public class ActivityName extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // remove title
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.main);
        }
 }
Luau answered 24/10, 2014 at 8:32 Comment(1)
But it is showing black space in place of taskbar. I want to remove this black space alsoAtmosphere
B
9

Update Answer I added android:windowIsTranslucent in case you have white screen in start of activity

just create new Style in values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- to hide white screen in start of window -->
    <item name="android:windowIsTranslucent">true</item>
    </style>

</resources>

from your AndroidManifest.xml add style to your activity

android:theme="@style/AppTheme"

to be like this

<activity android:name=".Splash"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
Bubbler answered 10/9, 2015 at 7:42 Comment(0)
C
9

Simply declare in styles.xml

  <style name="AppTheme.Fullscreen" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
  </style>

Then use in menifest.xml

    <activity
        android:name=".activities.Splash"
        android:theme="@style/AppTheme.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Chill Pill :)

Calisa answered 28/3, 2020 at 10:32 Comment(0)
C
7

According to this document, add the following code to onCreate

getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
        SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION   | 
        SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Coverlet answered 16/8, 2019 at 14:44 Comment(0)
O
6

In onCreate call

requestWindowFeature(Window.FEATURE_NO_TITLE); // for hiding title

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
Orb answered 5/4, 2015 at 8:47 Comment(0)
S
4

You can use the following codes to have a full page in android

Step 1 : Make theme in styles.xml section

<style name="AppTheme.Fullscreen" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Step 2 : Add theme on AndroidManifest.xml

<activity
android:name=“.Activity”
android:theme="@style/AppTheme.Fullscreen"/>

Step 3 : Java codes section

For example you can added following codes in to the onCreate() method.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Sahaptin answered 16/9, 2018 at 13:35 Comment(0)
H
3

If you Checkout the current Android Studio. You could create a New Activity with the Full-screen template. If you Create such an Activity. You could look into the basic code that Android Studio uses to switch between full-screen and normal mode.

Gallery Showing the Full-Screen Activity

This is the code I found in there. With some minor tweaks I'm sure you'll get what you need.

public class FullscreenActivity extends AppCompatActivity {
    private static final boolean AUTO_HIDE = true;
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
    private static final int UI_ANIMATION_DELAY = 300;
    private final Handler mHideHandler = new Handler();
    private View mContentView;
    private final Runnable mHidePart2Runnable = new Runnable() {
        @SuppressLint("InlinedApi")
        @Override
        public void run() {
            // Delayed removal of status and navigation bar

            // Note that some of these constants are new as of API 16 (Jelly Bean)
            // and API 19 (KitKat). It is safe to use them, as they are inlined
            // at compile-time and do nothing on earlier devices.
            mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
    };
    private View mControlsView;
    private final Runnable mShowPart2Runnable = new Runnable() {
        @Override
        public void run() {
            // Delayed display of UI elements
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.show();
            }
            mControlsView.setVisibility(View.VISIBLE);
        }
    };
    private boolean mVisible;
    private final Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            hide();
        }
    };
    private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_fullscreen);

        mVisible = true;
        mControlsView = findViewById(R.id.fullscreen_content_controls);
        mContentView = findViewById(R.id.fullscreen_content);


        // Set up the user interaction to manually show or hide the system UI.
        mContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggle();
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.
        findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
    }
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }
    private void toggle() {
        if (mVisible) {
            hide();
        } else {
            show();
        }
    }
    private void hide() {
        // Hide UI first
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        mControlsView.setVisibility(View.GONE);
        mVisible = false;

        // Schedule a runnable to remove the status and navigation bar after a delay
        mHideHandler.removeCallbacks(mShowPart2Runnable);
        mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
    }
    @SuppressLint("InlinedApi")
    private void show() {
        // Show the system bar
        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        mVisible = true;

        // Schedule a runnable to display UI elements after a delay
        mHideHandler.removeCallbacks(mHidePart2Runnable);
        mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
    }
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

Now I went further to checkout how this could be done in a more simple fashion. Making changes to the AppTheme style in your styles.xml file would be most helpful. This changes all your activities to a Full Screen view.

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

If you want only some activities to look Full Screen, you could create a new AppTheme that extends your current app theme and include the above code in that new style that you created. This way, you just have to set style=yournewapptheme in the manifest of whichever activity you want to go Full Screen

Hadwyn answered 29/4, 2020 at 5:42 Comment(0)
T
1
fun Activity.showSystemUi() {
    this.window.decorView.systemUiVisibility = (
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            )
}
Trexler answered 17/1, 2022 at 11:27 Comment(1)
There are 14 existing answers to this question, including a top-voted, accepted answer with over eight votes. Are you certain your solution hasn't already been given? If not, why do you believe your approach improves upon the existing proposals, which have been validated by the community? Offering an explanation is always useful on Stack Overflow, but it's especially important where the question has been resolved to the satisfaction of both the OP and the community. Help readers out by explaining what your answer does different and when it might be preferred.Zolazoldi
K
1

This is my android manifest.xml which links to theme.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.brokenphysics.issb">
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ISSB">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

This is my theme.xml

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ISSB" parent="Theme.AppCompat.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

what ever I do I can't get the app to go fullscreen and hide the status and navigation bars.

Kinetics answered 17/5, 2022 at 18:27 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Reconvert
E
0

I recently had the exact same issue and benefitted from the following post as well (in addition to Rohit5k2's solution above):

https://bsgconsultancy.wordpress.com/2015/09/13/convert-any-website-into-android-application-by-using-android-studio/

In Step 3, MainActivity extends Activity instead of ActionBarActivity (as Rohit5k2 mentioned). Putting the NoTitleBar and Fullscreen theme elements into the correct places in the AndroidManifest.xml file is also very important (take a look at Step 4).

Elegant answered 14/9, 2015 at 12:27 Comment(0)
I
0

Add these to Activity of your application.

Android JAVA

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

;

Android Kotlin

supportActionBar?.hide()
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
Imtiaz answered 13/6, 2020 at 17:50 Comment(1)
Welcome to Stack Overflow. A little bit of context and explanation would greatly improve this answer. When adding an answer to an older question with existing answers it is important to point out what new aspect of the question your answer addresses and to note if the technologies involved have changed since the question was asked if that is relevant to your answer.Kado
K
0

you can do make App in FullScreen Mode form just one line code. i am using this in my code.

just set AppTheme -> Theme.AppCompat.Light.NoActionBar in your style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

It will work in all pages..

Kao answered 17/6, 2020 at 17:19 Comment(0)
B
0

Adding current working solution for 'FLAG_FULLSCREEN' is deprecated

Add the following to your theme in themes.xml

<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>

Worked perfectly for me.

Beacham answered 29/11, 2020 at 22:54 Comment(0)
B
0

this method works in new android and older

private fun changeScreenSystemUiController(isFullScreen: Boolean) {
    window?.also {
        WindowCompat.setDecorFitsSystemWindows(it, !isFullScreen)
        WindowCompat.getInsetsController(it, it.decorView).apply {
            systemBarsBehavior =
                if (isFullScreen)
                    WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                else
                    WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
            if (isFullScreen)
                hide(WindowInsetsCompat.Type.systemBars())
            else
                show(WindowInsetsCompat.Type.systemBars())
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            it.attributes.layoutInDisplayCutoutMode =
                if (isFullScreen)
                    WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
                else
                    WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
        }
    }
}
Brogle answered 29/3, 2023 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.