在AndroidManifest.xml的activity节点中设置
横屏: 更改为
android:screenOrientation="landscape"
竖屏:更改为
android:screenOrientation="portrait"
在代码中设置
强制竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
强制横屏 :
@Overrideprotected void onResume() {/*** 设置为横屏*/if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}super.onResume();}
设置全屏
在Activity的onCreate方法中的setContentView(R.layout.XXX)调用之前添加下面代码
requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
如果觉得《Android 强制设置横屏或竖屏》对你有帮助,请点赞、收藏,并留下你的观点哦!