Locking the game to full-screen and landscape orientation
We want to use every pixel that the player's Android device has to offer so we will make changes to the AndroidManifest.xml
file which allows us to make configuration changes.
Make sure the AndroidManifest.xml
file is open in the editor window. If you followed along with the previous section it will be already.
In the AndroidManifest.xml
file, locate the following line of code:
android:name=".SubHunter">
Place the cursor before the closing >
shown above. Tap the Enter key a couple of times to move the >
a couple of lines below the rest of the line shown above.
Immediately below ".SubHunter"
but before the newly positioned >
type or copy and paste these two lines to make the game run full screen and lock it in the landscape orientation.
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="landscape"
This is a fiddly set of steps and it is the first code we have edited in the book so here I am showing you a bigger range of this file with the code we just added highlighted amongst it.
… <activity android:name=".SubHunter" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="landscape" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> …
Tip
The code we have just written and the rest of the contents of AndroidManifest.xml
we call XML (extensible markup language). Android uses XML for several different configurations. It is not necessary to learn this language as to make all the projects in this book this minor modification is all we will ever need to do.
Now our game will use all the screen space the device makes available and the screen has been locked in landscape mode even if the player holds their device in portrait orientation.