Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using full screen Activity

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

like image 669
nabeel Avatar asked Oct 11 '15 19:10

nabeel


2 Answers

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>
like image 106
t-kashima Avatar answered Sep 28 '22 01:09

t-kashima


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.

like image 44
RominaV Avatar answered Sep 28 '22 03:09

RominaV