From 6baf619b089e796b052beead8b2f0bb83b41ba0a Mon Sep 17 00:00:00 2001 From: yxk2026 <10178404+yxk2026@user.noreply.gitee.com> Date: Sat, 30 Aug 2025 15:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=9F=BA=E4=BA=8EList=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=AE=9E=E7=8E=B0=E4=BA=8C=E7=BA=A7=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E6=95=88=E6=9E=9C=E3=80=91=E9=80=82=E9=85=8D=E6=B2=89=E6=B5=B8?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 129 ++++++++++++------ entry/src/main/ets/pages/IndexPage.ets | 8 ++ entry/src/main/ets/view/ClassityItem.ets | 2 +- 3 files changed, 93 insertions(+), 46 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 372a32e..6dea8a6 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,51 +1,90 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); - } - - onDestroy(): void { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/IndexPage', (err, data) => { - if (err.code) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + } + + onDestroy(): void { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/IndexPage', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + let errCode: number = err.code; + if (errCode) { + hilog.error(0x0000, 'testTag', 'Failed to obtain the main window. Cause: ', JSON.stringify(err)); + return; + } + try { + windowClass = data; + let isLayoutFullScreen = true; + windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + hilog.info(0x0000, 'testTag', 'Succeeded in setting the window layout to full-screen mode.'); + }); + let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); + // Set the height of the status bar. + AppStorage.setOrCreate('statusBarHeight', data.getUIContext().px2vp(avoidArea.topRect.height)); + AppStorage.setOrCreate('bottomHeight', data.getUIContext() + .px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)); + } catch (exception) { + hilog.error(0x0000, '[EntryAbility]', + `Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); + } + }) + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/IndexPage.ets b/entry/src/main/ets/pages/IndexPage.ets index 252c8ae..abcd8f4 100644 --- a/entry/src/main/ets/pages/IndexPage.ets +++ b/entry/src/main/ets/pages/IndexPage.ets @@ -23,6 +23,8 @@ import ClassifyViewModel from '../viewmodel/ClassifyViewModel'; @Entry @Component struct IndexPage { + @StorageLink('statusBarHeight') statusBarHeight: number = 0; + @StorageLink('bottomHeight') bottomHeight: number = 0; @State currentClassify: number = 0; // selected classify index. @State requestSuccess: boolean = false; // is loading data. private classifyList: Array = []; @@ -117,6 +119,12 @@ struct IndexPage { .width(Constants.FULL_PERCENT) } } + .padding({ + top: this.statusBarHeight, + bottom: this.bottomHeight + }) .backgroundColor($r('app.color.base_background')) + .height(Constants.FULL_PERCENT) + .width(Constants.FULL_PERCENT) } } \ No newline at end of file diff --git a/entry/src/main/ets/view/ClassityItem.ets b/entry/src/main/ets/view/ClassityItem.ets index ac25d91..ccf53f1 100644 --- a/entry/src/main/ets/view/ClassityItem.ets +++ b/entry/src/main/ets/view/ClassityItem.ets @@ -17,8 +17,8 @@ import Constants from '../common/constants/Constants'; @Component export default struct ClassifyItem { - classifyName?: ResourceStr; @Prop isSelected: boolean = false; + classifyName?: ResourceStr; onClickAction = (): void => {} build() { -- Gitee