Android full-screen mode [horizontal and vertical screen switching] stepping on daily life

Due to business needs, the video needs to be switched between horizontal and vertical screens. The horizontal screen status needs to be full screen, but the vertical screen does not. The pit has been filled, welcome to guide.
The core method of horizontal and vertical screen:
 

1: Dynamically set horizontal and vertical screens

// force vertical screen
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// force horizontal screen
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Equivalent to AndroidManifest.xml 

android:screenOrientation="portrait" // Set vertical screen display android:configChanges="orientation|keyboardHidden|screenSize" // Prevent recreation every time the screen switches
public void onConfigurationChanged(@NonNull Configuration newConfig) {
boolean orientationLandscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
    if(orientationLandscape) {
        // 横屏
    } else {
        // 竖屏 
    }

}

Other Orientation meanings

SCREEN_ORIENTATION_UNSET:
SCREEN_ORIENTATION_UNSPECIFIED: The default value, the orientation is chosen by the system. Its usage strategy, and the specific context in which it is selected, may vary from device to device.
SCREEN_ORIENTATION_LANDSCAPE: landscape display
SCREEN_ORIENTATION_PORTRAIT: vertical screen display
SCREEN_ORIENTATION_USER: use the user's current preferred orientation
SCREEN_ORIENTATION_BEHIND: Use the same orientation as the Activity below the Activity in the Activity stack. SCREEN_ORIENTATION_SENSOR: The displayed orientation is determined by the orientation sensor of the device. The orientation of the display depends on how the user holds the device; when the user rotates the device, the orientation of the display changes. However, by default, some devices do not rotate in all four directions, so to allow rotation in all four directions, use the fullSensor attribute value SCREEN_ORIENTATION_NOSENSOR: The display orientation of the screen will not refer to the physical orientation sensor. Sensors are ignored so the display doesn't rotate as the user moves the device. Other than this difference, the system uses the same strategy as the "unspecified" setting for rotating the screen's orientation.
SCREEN_ORIENTATION_SENSOR_LANDSCAPE: Horizontal display, but based on the device sensor, it can be displayed in the normal direction or reversed. It was introduced in API Level 9.
SCREEN_ORIENTATION_SENSOR_PORTRAIT: Portrait display, but based on the device sensor, it can be displayed in the normal direction or reversed. It was introduced in API Level 9.
SCREEN_ORIENTATION_REVERSE_LANDSCAPE: Displayed in reverse to the normal landscape orientation, introduced in API Level 9. SCREEN_ORIENTATION_REVERSE_PORTRAIT: Reverse the normal portrait orientation, introduced in API Level 9. SCREEN_ORIENTATION_FULL_SENSOR: The orientation of the display (4 orientations) is determined by the orientation sensor of the device. Except that it allows the screen to have 4 display orientations, the situation is similar to when it is set to "sensor". No matter what kind of device, usually will do so. For example, some devices do not normally use portrait inversion or landscape inversion, but with this setting, such inversion will still occur. This value was introduced in API Level 9.
SCREEN_ORIENTATION_USER_LANDSCAPE,
SCREEN_ORIENTATION_USER_PORTRAIT,
SCREEN_ORIENTATION_FULL_USER,
SCREEN_ORIENTATION_LOCKED

Two: full screen

Note that when the screen is turned, there is an exception in obtaining the width and height.
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) full screen, other parameters can be searched for window.addFlags.WindowManager.LayoutParams to get detailed information, thought this should end, but the result is still too young, the keyboard pop-up monitoring is invalid. The reason is that setting the full screen leads to 

Original author code reference link

addOnLayoutChangeListener() is invalid. After several twists and turns, it is found that PopupWindow can be used as a monitor. It should be noted that the monitor will be invalid when it is shown again after Popwindow.dismiss(), and it needs to re-register the monitor every time show()

Guess you like

Origin blog.csdn.net/ff_hh/article/details/120978509