Android(安卓)强制设置横屏或竖屏
16lz
2021-12-04
在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代码速查,写给新手的朋友们
- android 读取SQLite android could not open the database in re
- Java代码设置Android全屏
- android xml中设置自适应图片
- android Manifest.xml选项(转贴)
- ListView设置分割线Divider样式
- Android操作权限设置与Apk真正安全的缓存数据
- Appium-Drivers-UIAutomator2(Android)
- Android(安卓)StatusBar