HarmonyOS 页面如何将背景处理为透明

页面如何将背景处理为透明,现在有个场景比如A页面点击按钮,弹出B页面,B页面希望是头部有200的高度是透明到A页面,底部是B页面的内容。这种场景的话,要怎么把页面B设置为透明背景,让它上半部分可以透明到A页面。

HarmonyOS
2025-01-09 17:55:00
2343浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

可参考以下思路:

1、使用自定义弹框或者半模态弹框,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-methods-custom-dialog-box-V5

半模态参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5#bindsheet

2、使用创建子窗口加载pageB页面

// Page1.ets
import window from '@ohos.window';

@Entry
@Component
struct Page2 {
  @State message: string = 'page Page2';

  onPageHide() {
    console.log("pageHide")
  }

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        Button("pageB").onClick(() => {
          let windowStege: window.WindowStage = AppStorage.get("windowStage") as window.WindowStage;
          windowStege.createSubWindow("hello", (err, win) => {
            win.setUIContent('pages/Page2');
            win.showWindow();
          })
        })
      }
      .width('100%')
    }
    .height('100%')
    .backgroundColor(Color.Pink)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
// Page2.ets
import window from '@ohos.window';

@Entry
@Component
struct Index {
  @State message: string = 'page Index';

  aboutToAppear() {
    window.findWindow("hello").setWindowBackgroundColor("#00000000")
  }

  onBackPress() {
    window.findWindow("hello").destroyWindow().then((res) => {
      console.log("destroyWindow success")
    }).catch(() => {
      console.log("destroyWindow fail")
    })
    return true
  }

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
      .backgroundColor(Color.Red)
    }
    .alignItems(VerticalAlign.Top)
    .height('100%')
    .backgroundColor("#80ffffff")
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
//EntryAbility.ets
AppStorage.setAndLink("windowStage", windowStage);
  • 1.
  • 2.
分享
微博
QQ
微信
回复
2025-01-09 18:57:10


相关问题
如何将背景颜色设置透明
3357浏览 • 1回复 待解决
HarmonyOS 如何将page设置透明
635浏览 • 1回复 待解决
HarmonyOS List组如何将背景色设置透明
383浏览 • 1回复 待解决
如何设置卡片背景透明
3442浏览 • 1回复 待解决
如何将页面设置深色模式
2837浏览 • 1回复 待解决
HarmonyOS 如何设置页面背景透明
595浏览 • 1回复 待解决
HarmonyOS page页面如何设置半透明效果
570浏览 • 1回复 待解决
如何将Ability的UI界面设置成透明
2447浏览 • 1回复 待解决
page页面如何设置横屏显示
2270浏览 • 1回复 待解决
如何将har库迁移hsp库
1405浏览 • 1回复 待解决
HarmonyOS UIAbility如何设置透明背景
619浏览 • 1回复 待解决
HarmonyOS 如何设置背景透明
552浏览 • 1回复 待解决