HarmonyOS 鸿蒙Next 动态设置属性 attributeModifier RowAttribute/backgroundBlurStyle 不生效
HarmonyOS 鸿蒙Next 动态设置属性 attributeModifier RowAttribute/backgroundBlurStyle 不生效
实现向下滑动的时候 搜索框背景模糊 动态设置属性 attributeModifier RowAttribute/backgroundBlurStyle
不生效
class MyBackGroundModifier implements AttributeModifier<RowAttribute> {
isScroll: boolean = false;
bgColor: string = '';
applyNormalAttribute(instance: RowAttribute): void {
if (this.isScroll) {
instance.backgroundBlurStyle(BlurStyle.Thin, { inactiveColor: this.bgColor })
} else {
instance.backgroundColor(this.bgColor)
}
}
}
更多关于HarmonyOS 鸿蒙Next 动态设置属性 attributeModifier RowAttribute/backgroundBlurStyle 不生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
可以参考下这个demo能否满足你的需求
@Entry
@Component
struct Index1 {
@State radius: number = 0;
@State text: string = '';
@State y: string = '手指不在屏幕上';
aboutToAppear() {
this.text = "按住屏幕上下滑动\n" + "当前手指所在y轴位置 : " + this.y +
"\n" + "当前图片模糊程度为 : " + this.radius;
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text(this.text)
.height(200)
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontFamily("cursive")
.fontStyle(FontStyle.Italic)
TextInput({placeholder:'模糊实现'})
.blur(this.radius)// 使用blur接口为照片组件添加内容模糊效果
.width("100%")
.backgroundImage($r("app.media.111"))
}.height('100%')
.width("100%")
.onTouch((event?: TouchEvent) => {
if (event) {
if (event.type === TouchType.Move) {
this.y = Number(event.touches[0].y.toString()).toString();
this.radius = Number(this.y) / 10; // 根据跟手过程中的滑动距离修改模糊半径,配合模糊接口,形成跟手模糊效果
}
if (event.type === TouchType.Up) {
this.radius = 0;
this.y = '手指离开屏幕';
}
}
this.text = "按住屏幕上下滑动\n" + "当前手指所在y轴位置 : " + this.y +
"\n" + "当前图片模糊程度为 : " + this.radius;
})
}
}
更多关于HarmonyOS 鸿蒙Next 动态设置属性 attributeModifier RowAttribute/backgroundBlurStyle 不生效的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,attributeModifier
用于动态修改组件的属性,而RowAttribute/backgroundBlurStyle
用于设置背景模糊样式。如果backgroundBlurStyle
不生效,可能的原因包括:
-
组件层级问题:
backgroundBlurStyle
可能被其他样式或属性覆盖。确保Row
组件层级中不存在覆盖背景模糊样式的其他样式。 -
属性优先级:检查是否有其他更高优先级的属性或样式影响了
backgroundBlurStyle
。鸿蒙系统中,某些属性可能具有更高的优先级,导致backgroundBlurStyle
失效。 -
系统版本兼容性:确认使用的鸿蒙系统版本是否支持
backgroundBlurStyle
。某些版本可能对该属性的支持不完全,导致不生效。 -
代码逻辑错误:检查
attributeModifier
的代码逻辑,确保在正确的时间和条件下调用backgroundBlurStyle
。错误的调用时机或条件可能导致属性未正确应用。 -
硬件限制:某些设备可能不支持背景模糊效果,或者硬件性能不足以渲染该效果,导致
backgroundBlurStyle
不生效。 -
API使用错误:确认
backgroundBlurStyle
的API调用方式是否正确,参数是否符合要求。错误的API使用可能导致属性无法正常应用。
总结,backgroundBlurStyle
不生效可能由组件层级、属性优先级、系统版本、代码逻辑、硬件限制或API使用错误引起。需逐一排查这些因素以确定具体原因。