Change screen orientation in Android without reloading the activity

前端 未结 5 744
梦谈多话
梦谈多话 2020-12-16 10:40

I want to change the orientation programmatically while running my Android App, with these lines of code:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA         


        
5条回答
  •  情书的邮戳
    2020-12-16 10:50

    Call this method And Set manifest file

    android:configChanges="orientation|screenSize|keyboardHidden"
    
    public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
    
            // Checks the orientation of the screen
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
                Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
            }
        }
    

提交回复
热议问题