Using full screen Activity
Asked Answered
R

6

12

I am making a simple game and so far I've been using the Blank Activity. Now I want it to cover the entire screen, Will I need to Recode the entire thing using a FullScreen Activity? I've tried looking for something online but every thing i came across had adding this bit:​

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);

Which causes the app to crash as soon as it is launched on a device. SO please if anyone can show me my error.

Here is a link to the logcat output as well as the game code

Logcat and game code

Rossuck answered 11/10, 2015 at 19:54 Comment(3)
Show us your Logcat, and we'll show you the error.Marinelli
Add it to your question.Marinelli
Already did, But since the Logcat was too long I uploaded a link to the file using google docs.Rossuck
D
30

Try this to set activity to fullscreen:

getWindow().getDecorView().setSystemUiVisibility(
  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

You can put this code in onCreate() method

Doggish answered 11/10, 2015 at 19:57 Comment(4)
Essentially This wasn't first working as I had the target SDK set all the way back to Froyo. Once I changed that to KitKat, This worked like a charmRossuck
@Michele Lacorte I am experiencing a white coloured bar when my navigation drawer goes off in android L?Terylene
I think @t-kashima xml solution below in the answers is quite nice. Check it out. No need to duplicate this accepted answers' code everywhere if you have a style that defines fullscreen.Oneway
Tried this. The activity only looks fullscreen after onCreate, but the status bar appears when the activity is resumed. XML solution works better.Etter
L
26

You can try following code.

style.xml:

<style name="AppTheme.NoTitle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

AndroidManifest.xml:

<activity
    android:name=".FullScreenActivity"
    android:theme="@style/AppTheme.NoTitle"
    android:screenOrientation="portrait"
    android:launchMode="singleTop">
</activity>
Lauree answered 12/10, 2015 at 6:43 Comment(2)
best solution is here i think.Should have more upvotes.Lipetsk
Upvoted, but it doesn't work well. Tested it and it shows the soft buttons when resuming the activity.Etter
E
4

None of the answers above works correctly; they have problems with the onResume() method, and end up showing the soft keys.

The correct way to do it is pretty straightforward. Override this method in the Activity that should be fullscreen:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

That's if you want "Sticky Immersion". Check out the full doc here, and decide what is better for your use case.

Etter answered 24/3, 2017 at 18:53 Comment(2)
Thank you! This should be the accepted answer. I had this in onResume() as so many stack overflow answers suggest, and it worked 99% of the time, making it hard to debug. You saved me having to run this code every few seconds as a workaround.Proterozoic
@user1516661 I was confused at first with everyone saying to put it on the onResume() method too :)Etter
T
2

What you wanted is called Imersive mode, which works on Android 4.4 and Above

getWindow().getDecorView().setSystemUiVisibility(
  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

Official Documentation can be found here

Thermidor answered 1/6, 2016 at 6:27 Comment(0)
M
2

In AndroidManifest.xml file

<activity
       android:name=".Launch"
       android:label="@string/app_name"
       android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->

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

and your class should extends Activity not AppCompatActivity...

Manful answered 9/8, 2016 at 6:34 Comment(0)
F
0

You can simply go to your manifest file and add android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to your <activity /> or <application /> tag in your Manifest file depending upon your requirement.

Funda answered 11/10, 2015 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.