From 6ed73ebeb3262d649bda0fcf9f6da3b59e4c205d Mon Sep 17 00:00:00 2001 From: ywcoder <1104410818@qq.com> Date: Tue, 5 Aug 2025 09:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EFAQ=EF=BC=9A=E5=A6=82?= =?UTF-8?q?=E4=BD=95=E9=92=88=E5=AF=B9UI=E7=BB=84=E4=BB=B6=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=81=9AAPI=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...omponentAttributeCompatibilityJudgment.ets | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ArkUI/entry/src/main/ets/pages/ComponentAttributeCompatibilityJudgment.ets diff --git a/ArkUI/entry/src/main/ets/pages/ComponentAttributeCompatibilityJudgment.ets b/ArkUI/entry/src/main/ets/pages/ComponentAttributeCompatibilityJudgment.ets new file mode 100644 index 0000000..1f80c19 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/ComponentAttributeCompatibilityJudgment.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 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. +*/ + +/* +* FAQ:如何针对UI组件属性做API版本兼容性判断 +*/ + +// [Start component_attribute_compatibility_judgment] +import { deviceInfo } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct ComponentAttributeCompatibilityJudgment { + modifier: MyListModifier = new MyListModifier(); + + build() { + List() { + // 列表内容 + } + .height('100%') + .width('100%') + .attributeModifier(this.modifier) + } +} + +class MyListModifier implements AttributeModifier { + applyNormalAttribute(instance: ListAttribute): void { + // 通过deviceInfo的api版本信息进行判断 + if (deviceInfo.sdkApiVersion > 14) { + // 要适配的是List组件的backToTop属性 + // instance为List的属性对象,可以通过instance对象对属性进行修改 + instance.backToTop(true); + } + } +} + +// [End component_attribute_compatibility_judgment] -- Gitee