鸿蒙如何监听手机旋转,横竖屏
步骤一,config.json
在config.json中的abilities下某一个ability中监听,在下面添加"configChanges":[“orientation”]
步骤二,在Ability或AbilitySlice中
在Ability或AbilitySlice中重写
@Override
protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) {
super.onOrientationChanged(displayOrientation);
if (displayOrientation == AbilityInfo.DisplayOrientation.PORTRAIT) {//竖屏
} else if (displayOrientation == AbilityInfo.DisplayOrientation.LANDSCAPE) {//横屏
}
}