我的需求是APP大部分是竖屏显示,在某个页面需要显示横屏。
直接上答案
1、在EntryAbility中获取globalThis.windowClass
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
//保存globalThis.windowClass
globalThis.windowClass = data
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
});
windowStage.loadContent('pages/BarrageTabPage', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '