component如何设置全局透明等主题配置?

目前flutter想打开一个harmony native的dialog,需要一个中间层透明容器,这个容器可以设置为透明吗?怎么设置

阅读 529
1 个回答

解决方案:

可使用@ohos.promptAction (弹窗),示例代码:

import promptAction from '@ohos.promptAction';
import { BusinessError } from '@ohos.base';

function showDialog() {
  try {
    promptAction.showDialog({
      title: 'showDialog Title Info',
      message: 'Message Info',
      isModal: true,
      showInSubWindow: true,
      alignment: DialogAlignment.Center,
      buttons: [
        {
          text: 'button1',
          color: '#000000'
        },
      ]
    }, (err, data) => {
      if (err) {
        console.info('showDialog err: ' + err);
        return;
      }
      console.info('showDialog success callback, click button: ' + data.index);
    });
  } catch (error) {
    let message = (error as BusinessError).message
    let code = (error as BusinessError).code
    console.error(`showDialog args error code is ${code}, message is ${message}`);
  };
}

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

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        Button('showDialog ', { stateEffect: true, type: ButtonType.Capsule })
          .width('80%')
          .height(40)
          .margin(20)
          .onClick(() => {
            showDialog()
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进