从代码中将方向设置为纵向

Luk*_*kap 2 android portrait manifest orientation screen-orientation

我知道我可以限制清单文件的方向.像这样

android:screenOrientation="portrait"
Run Code Online (Sandbox Code Playgroud)

但是可以从代码中设置方向吗?

例如,可以从清单和代码中将活动设置为全屏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

And*_*son 13

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Run Code Online (Sandbox Code Playgroud)