我正在构建一个react原生应用程序,我想为android平板电脑启用(纵向+横向(模式,为android手机启用纵向模式。
我知道iPad/iPhone的解决方案,所以如果有人能帮助我进行安卓配置,那就太好了
请将以下代码添加到android/app/src/main/java.com/[您的项目名称]/MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}
之后创建三个bools.xml文件
android/app/src/main/res/values/bools.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">true</bool>
</resources>
android/app/src/main/res/values-sw600dp/bools.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>
android/app/src/main/res/values xlarge/bools.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>