Full Screen
Add the following code before calling setcontentview (myview) in the oncreate method of activity.
Requestwindowfeature (window. feature_no_title); // hide the title
Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); // set the full screen landscape
Modify the onresume method of the activity according to the following code example:
@ Override protected void onresume (){
/*** Set to landscape screen */
If (getrequestedorientation ()! = Activityinfo. screen_orientation_landscape ){
Setrequestedorientation (activityinfo. screen_orientation_landscape );
}
Super. onresume ();
} Or add the Android: screenorientation attribute to the activity node in the configuration file (landscape is landscape and portrait is portrait)
Android: launchmode = "singletask" Android: screenorientation = "portrait"> set the screen to screen_orientation_portrait.
Note: Each activity has this screenorientation attribute. You must set this attribute for each activity. You can set this attribute to a portrait screen (portrait) or a non-gravity sensor (nosensor ).
Solution to keep the program interface in one direction and not change with the orientation of the mobile phone:
Configure androidmanifest. xml. Add this line to Android: screenorientation = "Landscape ".
For example, (landscape is horizontal and portrait is vertical ):
Java code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Ray. linkit"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". Main"
Android: Label = "@ string/app_name"
Android: screenorientation = "portrait">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity Android: Name = ". gameplay"
Android: screenorientation = "portrait"> </activity>
<Activity Android: Name = ". optionview"
Android: screenorientation = "portrait"> </activity>
</Application>
<Uses-SDK Android: minsdkversion = "3"/>
</Manifest>
In addition, the activity is restarted every time the screen is switched on in Android. Therefore, you should save the status of the current activity before the activity is destroyed and load the configuration when the activity is created again, in progress, the game will not automatically restart!
Some programs are suitable for switching from a portrait screen to a landscape screen, or vice versa. What should we do at this time? You can configure Android: screenorientation = "portrait" in the activity configuration area ". In this way, you can ensure that the portrait screen is always portrait or landscape.
Some programs are suitable for switching between landscape and landscape screens. What should we do? First, you must configure the activity as follows: Android: configchanges = "keyboardhidden | orientation". In addition, you must override the onconfigurationchanged method of the activity. The implementation method is as follows:
@ Override
Public void onconfigurationchanged (configuration newconfig ){
Super. onconfigurationchanged (newconfig );
If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape ){
// Land do nothing is OK
} Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait ){
// Port do nothing is OK
}
}