[Android] How to disable the screen orientation?

Below utility are got from the web:

    private static int _oldScreenOrientation;
    public static void disableScreenOrientation() {
        _oldScreenOrientation = activity.getRequestedOrientation();
        
        if(isLandscape())
            activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        else
            activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    
    public static void restoreScreenOrientation() {
        activity.setRequestedOrientation(_oldScreenOrientation);
    }

转载于:https://www.cnblogs.com/jalenwang/archive/2012/12/05/2803246.html

猜你喜欢

转载自blog.csdn.net/weixin_34099526/article/details/93939369