1

我正在开发一个 Harmony 应用程序,我想在其中创建一个带有自定义组件的弹出对话框。
我试过这个

Component customComponent = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_custom_dialog, null, false);
// I have already made custom component
PopupDialog popupDialog = new PopupDialog(getContext, customComponent);
popupDialog.show();

运行此之后,我只看到一个白色背景框并且自定义组件不可见。
为什么new PopupDialog(getContext, customComponent);不设置 customComponent.

4

2 回答 2

1

请检查自定义组件的高度和宽度是否正确设置。

或者您可以在实例化弹出对话框时分配值,例如 -

PopupDialog popupDialog = new PopupDialog(getContext(), associated, width, height);

此外,您需要在显示之前将自定义组件设置为弹出对话框 -

popupDialog.setCustomComponent(组件);

这是来自 HarmonyOS 开发者网站的示例

https://developer.harmonyos.com/en/docs/documentation/doc-guides/faq-java-developing-0000001073311795

于 2021-08-03T20:12:45.223 回答
0
new PopupDialog(getContext, customComponent);

上面的构造函数调用只会获取构造函数中传入的customComponent的高度和宽度。

要自定义弹出对话框的内容,需要使用以下API

public PopupDialog setCustomComponent​(Component customComponent)

您可以参考此文档以获取更多信息

于 2021-08-05T06:41:57.413 回答